save
This commit is contained in:
@@ -10,7 +10,8 @@ import { get, set } from 'idb-keyval'
|
||||
|
||||
import { useRoute } from "vue-router";
|
||||
import { DictId } from "@/types/types.ts";
|
||||
import { APP_VERSION, LOCAL_FILE_KEY, SAVE_DICT_KEY, SAVE_SETTING_KEY } from "@/config/env.ts";
|
||||
import { APP_VERSION, CAN_REQUEST, LOCAL_FILE_KEY, SAVE_DICT_KEY, SAVE_SETTING_KEY } from "@/config/env.ts";
|
||||
import { syncSetting } from "@/apis";
|
||||
|
||||
const store = useBaseStore()
|
||||
const runtimeStore = useRuntimeStore()
|
||||
@@ -50,6 +51,9 @@ watch(store.$state, (n: BaseState) => {
|
||||
|
||||
watch(settingStore.$state, (n) => {
|
||||
set(SAVE_SETTING_KEY.key, JSON.stringify({val: n, version: SAVE_SETTING_KEY.version}))
|
||||
if (CAN_REQUEST) {
|
||||
syncSetting(null, settingStore.$state)
|
||||
}
|
||||
})
|
||||
|
||||
async function init() {
|
||||
|
||||
@@ -13,25 +13,37 @@ function remove(data?: any) {
|
||||
}
|
||||
|
||||
export function dictListVersion() {
|
||||
return http<number>('dicts/dictListVersion', null, null, 'get')
|
||||
return http<number>('dict/dictListVersion', null, null, 'get')
|
||||
}
|
||||
|
||||
export function myDictList(params?) {
|
||||
return http('dicts/myDictList', null, params, 'get')
|
||||
return http('dict/myDictList', null, params, 'get')
|
||||
}
|
||||
|
||||
export function add2MyDict(data) {
|
||||
return http('dicts/add2MyDict', remove(data), null, 'post')
|
||||
return http('dict/add2MyDict', remove(data), null, 'post')
|
||||
}
|
||||
|
||||
export function addStat(data) {
|
||||
return http('dicts/addStat', data, null, 'post')
|
||||
return http('dict/addStat', data, null, 'post')
|
||||
}
|
||||
|
||||
export function detail(params?, data?) {
|
||||
return http<Dict>('dicts/detail', data, params, 'get')
|
||||
return http<Dict>('dict/detail', data, params, 'get')
|
||||
}
|
||||
|
||||
export function setDictProp(params?, data?) {
|
||||
return http<Dict>('dicts/setDictProp', remove(data), remove(params), 'post')
|
||||
return http<Dict>('dict/setDictProp', remove(data), remove(params), 'post')
|
||||
}
|
||||
|
||||
export function syncSetting(params?, data?) {
|
||||
return http<Dict>('dict/syncSetting', remove(data), remove(params), 'post')
|
||||
}
|
||||
|
||||
export function getSetting(params?, data?) {
|
||||
return http<Dict>('dict/getSetting', remove(data), remove(params), 'get')
|
||||
}
|
||||
|
||||
export function addDict(params?, data?) {
|
||||
return http<Dict>('dict/addDict', remove(data), remove(params), 'post')
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ export function useEventListener(type: string, listener: EventListenerOrEventLis
|
||||
e.ctrlKey = false
|
||||
e.altKey = false
|
||||
e.shiftKey = false
|
||||
//@ts-ignore
|
||||
listener(e)
|
||||
e.target.value = '1'
|
||||
})
|
||||
|
||||
@@ -85,6 +85,7 @@ async function init() {
|
||||
if (!runtimeStore.editDict?.articles?.length
|
||||
&& !runtimeStore.editDict?.custom
|
||||
&& ![DictId.articleCollect].includes(runtimeStore.editDict.en_name || runtimeStore.editDict.id)
|
||||
&& !runtimeStore.editDict?.is_default
|
||||
) {
|
||||
loading = true
|
||||
let r = await _getDictDataByUrl(runtimeStore.editDict, DictType.article)
|
||||
@@ -96,7 +97,7 @@ async function init() {
|
||||
let res = await detail({id: runtimeStore.editDict.id})
|
||||
if (res.success) {
|
||||
runtimeStore.editDict.statistics = res.data.statistics
|
||||
if (res.data.articles.length){
|
||||
if (res.data.articles.length) {
|
||||
runtimeStore.editDict.articles = res.data.articles
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import {Dict, DictId, DictType} from "@/types/types.ts";
|
||||
import {cloneDeep} from "@/utils";
|
||||
import { Dict, DictId, DictType } from "@/types/types.ts";
|
||||
import { cloneDeep } from "@/utils";
|
||||
import Toast from '@/components/base/toast/Toast.ts'
|
||||
import {onMounted, reactive} from "vue";
|
||||
import {useRuntimeStore} from "@/stores/runtime.ts";
|
||||
import {useBaseStore} from "@/stores/base.ts";
|
||||
import { onMounted, reactive } from "vue";
|
||||
import { useRuntimeStore } from "@/stores/runtime.ts";
|
||||
import { useBaseStore } from "@/stores/base.ts";
|
||||
import BaseButton from "@/components/BaseButton.vue";
|
||||
import {getDefaultDict} from "@/types/func.ts";
|
||||
import {Option, Select} from "@/components/base/select";
|
||||
import { getDefaultDict } from "@/types/func.ts";
|
||||
import { Option, Select } from "@/components/base/select";
|
||||
import BaseInput from "@/components/base/BaseInput.vue";
|
||||
import Form from "@/components/base/form/Form.vue";
|
||||
import FormItem from "@/components/base/form/FormItem.vue";
|
||||
import { CAN_REQUEST } from "@/config/env.ts";
|
||||
import { addDict } from "@/apis";
|
||||
|
||||
const props = defineProps<{
|
||||
isAdd: boolean,
|
||||
@@ -35,6 +37,7 @@ const DefaultDictForm = {
|
||||
}
|
||||
let dictForm: any = $ref(cloneDeep(DefaultDictForm))
|
||||
const dictFormRef = $ref()
|
||||
let loading = $ref(false)
|
||||
const dictRules = reactive({
|
||||
name: [
|
||||
{required: true, message: '请输入名称', trigger: 'blur'},
|
||||
@@ -43,9 +46,10 @@ const dictRules = reactive({
|
||||
})
|
||||
|
||||
async function onSubmit() {
|
||||
await dictFormRef.validate((valid) => {
|
||||
await dictFormRef.validate(async (valid) => {
|
||||
if (valid) {
|
||||
let data: Dict = getDefaultDict(dictForm)
|
||||
data.type = props.isBook ? DictType.article : DictType.word
|
||||
let source = [store.article, store.word][props.isBook ? 0 : 1]
|
||||
//todo 可以检查的更准确些,比如json对比
|
||||
if (props.isAdd) {
|
||||
@@ -54,6 +58,16 @@ async function onSubmit() {
|
||||
Toast.warning('已有相同名称!')
|
||||
return
|
||||
} else {
|
||||
if (CAN_REQUEST) {
|
||||
loading = true
|
||||
let res = await addDict(null, data)
|
||||
loading = false
|
||||
if (res.success) {
|
||||
data = getDefaultDict(res.data)
|
||||
} else {
|
||||
return Toast.error(res.msg)
|
||||
}
|
||||
}
|
||||
source.bookList.push(cloneDeep(data))
|
||||
runtimeStore.editDict = data
|
||||
emit('submit')
|
||||
@@ -62,7 +76,7 @@ async function onSubmit() {
|
||||
} else {
|
||||
let rIndex = source.bookList.findIndex(v => v.id === data.id)
|
||||
//任意修改,都将其变为自定义词典
|
||||
if (!data.custom && ![DictId.wordKnown, DictId.wordWrong, DictId.wordCollect, DictId.articleCollect].includes(data.id)) {
|
||||
if (!data.custom && ![DictId.wordKnown, DictId.wordWrong, DictId.wordCollect, DictId.articleCollect].includes(data.en_name || data.id)) {
|
||||
data.custom = true
|
||||
data.id += '_custom'
|
||||
}
|
||||
@@ -104,7 +118,7 @@ onMounted(() => {
|
||||
<FormItem label="描述">
|
||||
<BaseInput v-model="dictForm.description" textarea/>
|
||||
</FormItem>
|
||||
<FormItem label="原文语言">
|
||||
<FormItem label="原文语言" v-if="false">
|
||||
<Select v-model="dictForm.language" placeholder="请选择选项">
|
||||
<Option label="英语" value="en"/>
|
||||
<Option label="德语" value="de"/>
|
||||
@@ -112,7 +126,7 @@ onMounted(() => {
|
||||
<Option label="代码" value="code"/>
|
||||
</Select>
|
||||
</FormItem>
|
||||
<FormItem label="译文语言">
|
||||
<FormItem label="译文语言" v-if="false">
|
||||
<Select v-model="dictForm.translateLanguage" placeholder="请选择选项">
|
||||
<Option label="中文" value="zh-CN"/>
|
||||
<Option label="英语" value="en"/>
|
||||
@@ -122,7 +136,7 @@ onMounted(() => {
|
||||
</FormItem>
|
||||
<div class="center">
|
||||
<base-button type="info" @click="emit('close')">关闭</base-button>
|
||||
<base-button type="primary" @click="onSubmit">确定</base-button>
|
||||
<base-button type="primary" :loading="loading" @click="onSubmit">确定</base-button>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import {defineStore} from "pinia"
|
||||
import {checkAndUpgradeSaveSetting, cloneDeep} from "@/utils";
|
||||
import {DefaultShortcutKeyMap} from "@/types/types.ts";
|
||||
import {get} from "idb-keyval";
|
||||
import { APP_VERSION, SAVE_SETTING_KEY } from "@/config/env.ts";
|
||||
import { defineStore } from "pinia"
|
||||
import { checkAndUpgradeSaveSetting, cloneDeep } from "@/utils";
|
||||
import { DefaultShortcutKeyMap } from "@/types/types.ts";
|
||||
import { get } from "idb-keyval";
|
||||
import { CAN_REQUEST, SAVE_SETTING_KEY } from "@/config/env.ts";
|
||||
import { getSetting } from "@/apis";
|
||||
|
||||
export interface SettingState {
|
||||
soundType: string,
|
||||
@@ -120,6 +121,12 @@ export const useSettingStore = defineStore('setting', {
|
||||
configStr = configStr2
|
||||
}
|
||||
let data = checkAndUpgradeSaveSetting(configStr)
|
||||
if (CAN_REQUEST) {
|
||||
let res = await getSetting()
|
||||
if (res.success) {
|
||||
Object.assign(data, res.data)
|
||||
}
|
||||
}
|
||||
this.setState({...data, load: true})
|
||||
resolve(true)
|
||||
})
|
||||
|
||||
@@ -66,9 +66,16 @@ export function getDefaultDict(val: Partial<Dict> = {}): Dict {
|
||||
perDayStudyNumber: 20,
|
||||
custom: false,
|
||||
complete: false,
|
||||
|
||||
createdBy: '',
|
||||
en_name: '',
|
||||
category_id: null,
|
||||
is_default: false,
|
||||
|
||||
...val,
|
||||
words: shallowReactive(val.words ?? []),
|
||||
articles: shallowReactive(val.articles ?? []),
|
||||
statistics: shallowReactive(val.statistics ?? [])
|
||||
statistics: shallowReactive(val.statistics ?? []),
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,6 @@ export type DictResource = {
|
||||
name: string
|
||||
description: string
|
||||
url: string
|
||||
en_name?: string
|
||||
length: number
|
||||
category: string
|
||||
tags: string[]
|
||||
@@ -169,6 +168,11 @@ export interface Dict extends DictResource {
|
||||
statistics: Statistics[],
|
||||
custom: boolean,//是否是自定义词典
|
||||
complete: boolean,//是否学习完成,学完了设为true,然后lastLearnIndex重置
|
||||
//后端字段
|
||||
en_name?: string
|
||||
createdBy?: string
|
||||
category_id?: number
|
||||
is_default?: boolean
|
||||
}
|
||||
|
||||
export interface ArticleItem {
|
||||
|
||||
Reference in New Issue
Block a user