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

View File

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