This commit is contained in:
2024-12-19 23:03:52 +08:00
parent 901f273d2b
commit b89cef5b7c
2 changed files with 15 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
import { useStorage } from "@vueuse/core" import { useStorage } from "@vueuse/core"
import copyTextToClipboard from "copy-text-to-clipboard" import copyTextToClipboard from "copy-text-to-clipboard"
import queryString from "query-string" import qs from "query-string"
import { reactive, ref, watch } from "vue" import { reactive, ref, watch } from "vue"
import { getCodeByQuery, submit } from "../api" import { getCodeByQuery, submit } from "../api"
import { sources } from "../templates" import { sources } from "../templates"
@@ -63,7 +63,7 @@ export async function init() {
size.value = cache.fontsize.value size.value = cache.fontsize.value
status.value = Status.NotStarted status.value = Status.NotStarted
const parsed = queryString.parse(location.search) const parsed = qs.parse(location.search)
const base64 = parsed.share as string const base64 = parsed.share as string
if (base64) { if (base64) {
try { try {
@@ -91,10 +91,8 @@ export function reset() {
cache.code[code.language].value = sources[code.language] cache.code[code.language].value = sources[code.language]
output.value = "" output.value = ""
status.value = Status.NotStarted status.value = Status.NotStarted
const u = new URL(window.location.href) const url = qs.exclude(location.href, ["query"])
u.hash = "" window.location.href = url
u.search = ""
window.location.href = u.href
} }
export async function run() { export async function run() {
@@ -120,6 +118,6 @@ export function share() {
} }
const base64 = utoa(JSON.stringify(data)) const base64 = utoa(JSON.stringify(data))
copyTextToClipboard( copyTextToClipboard(
queryString.stringifyUrl({ url: location.href, query: { share: base64 } }), qs.stringifyUrl({ url: location.href, query: { share: base64 } }),
) )
} }

View File

@@ -1,26 +1,23 @@
<template> <template>
<n-flex vertical size="large"> <n-flex vertical size="large">
<n-flex v-if="code.value"> <n-flex v-if="code.value">
<n-flex align="center"> <div>
<span>复制当前代码输入 Query</span> <n-input v-model:value="query" />
<div> </div>
<n-input v-model:value="query" />
</div>
</n-flex>
<n-button type="primary" @click="create" :disabled="!query.length"> <n-button type="primary" @click="create" :disabled="!query.length">
新建 新建
</n-button> </n-button>
</n-flex> </n-flex>
<span v-else style="color: red">当前无代码</span> <div v-else style="color: red">当前无代码</div>
<n-flex> <n-flex>
<div style="margin-top: 6px" v-if="codes.length">已有的 Query</div> <div style="margin-top: 6px" v-if="codes.length">已有的</div>
<n-tag <n-tag
v-for="item in codes" v-for="item in codes"
:key="item.query" :key="item.query"
closable closable
size="large" size="large"
round round
@click="show(item.code)" @click="show(item.code, item.query)"
@close="remove(item.id)" @close="remove(item.id)"
> >
{{ item.query }} {{ item.query }}
@@ -33,6 +30,7 @@ import { useMessage } from "naive-ui"
import { onMounted, ref } from "vue" import { onMounted, ref } from "vue"
import { createCode, listCode, removeCode } from "../api" import { createCode, listCode, removeCode } from "../api"
import { code } from "../composables/code" import { code } from "../composables/code"
import qs from "query-string"
const message = useMessage() const message = useMessage()
@@ -56,8 +54,10 @@ async function remove(id: number) {
list() list()
} }
function show(codeStr: string) { function show(codeStr: string, query: string) {
code.value = codeStr code.value = codeStr
const url = qs.stringifyUrl({ url: location.href, query: { query } })
window.location.href = url
} }
async function list() { async function list() {