添加数据字典本地缓存,避免每次都去后端获取

This commit is contained in:
ywyonui 2025-07-15 22:29:36 +08:00
parent 7ac4b946f6
commit 01f8d740b9
15 changed files with 92 additions and 48 deletions

View File

@ -95,10 +95,11 @@
<script setup lang="ts">
import {onMounted, ref} from "vue";
import BasicLayout from "@/components/BasicLayout/Layout.vue";
import {dicApi} from "@/api/system/dic";
import { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data";
import { jsdXkXsListApi, jsdXkdmListApi } from "@/api/base/server";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
import dayjs from "dayjs";
@ -155,7 +156,7 @@ const getStatusClass = (status: string) => {
const loadStatusOptions = async () => {
try {
// pid763939514
const res = await dicApi({pid: 763939514});
const res = await findByPid({pid: 763939514});
if (res && res.result) {
statusOptions.value = res.result.map((item: any) => {
return {

View File

@ -101,7 +101,8 @@
<script setup lang="ts">
import {onMounted, ref} from "vue";
import BasicLayout from "@/components/BasicLayout/Layout.vue";
import {dicApi} from "@/api/system/dic";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
//
const studentList = ref([
@ -200,7 +201,7 @@ const getStatusClass = (status: string) => {
const fetchStatusOptions = async () => {
try {
// pid810984651
const res = await dicApi({pid: 810984651});
const res = await findByPid({pid: 810984651});
if (res && res.result) {
statusOptions.value = res.result.map((item: any) => {
return {

View File

@ -42,10 +42,11 @@
import {ref, onMounted} from "vue";
import { useLayout } from "@/components/BasicListLayout/hooks/useLayout";
import { dbListApi } from "@/api/base/server";
import { dicApi } from "@/api/system/dic";
import { getTimeAgo } from "@/utils/dateUtils";
import { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
const { setDb } = useDataStore();
const { getUser } = useUserStore();
@ -55,7 +56,7 @@ const dbLxMap = ref<any>({});
const fetchDbLxMap = async () => {
try {
//
const res = await dicApi({pid: 186148807});
const res = await findByPid({pid: 186148807});
if (res && res.result) {
// res.resultlistkeydictionaryValuevaluedictionary
dbLxMap.value = res.result.reduce((acc: any, item: any) => {

View File

@ -37,11 +37,11 @@
</template>
<script lang="ts" setup>
import { dicApi } from "@/api/system/dic";
import { useForm } from "@/components/BasicForm/hooks/useForm";
import { useDataStore } from "@/store/modules/data";
import { navigateBack, navigateTo } from "@/utils/uniapp";
import { cloneDeep, map } from "lodash";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
const schema = reactive<FormsSchema[]>([
{
@ -49,7 +49,7 @@ const schema = reactive<FormsSchema[]>([
label: "与本人关系",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 1066646708 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",

View File

@ -47,11 +47,11 @@
</template>
<script lang="ts" setup>
import { dicApi } from "@/api/system/dic";
import { useForm } from "@/components/BasicForm/hooks/useForm";
import { useDataStore } from "@/store/modules/data";
import { navigateTo, navigateBack } from "@/utils/uniapp";
import { cloneDeep, map } from "lodash";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
const schema = reactive<FormsSchema[]>([
{
@ -59,7 +59,7 @@ const schema = reactive<FormsSchema[]>([
label: "与本人关系",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 1066646708 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",

View File

@ -43,9 +43,7 @@
</template>
<script lang="ts" setup>
import { dicApi } from "@/api/system/dic";
import { useDataStore } from "@/store/modules/data";
import { navigateBack, navigateTo, showModal, showToast } from "@/utils/uniapp";
import { showToast } from "@/utils/uniapp";
import { cloneDeep, map } from "lodash";
import { fractionRuleApi } from "@/api/base/server";

View File

@ -49,10 +49,11 @@
</template>
<script lang="ts" setup>
import { dicApi } from "@/api/system/dic";
import { useDataStore } from "@/store/modules/data";
import { navigateBack, navigateTo } from "@/utils/uniapp";
import { cloneDeep, map } from "lodash";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
import dayjs from "dayjs";
//
@ -84,7 +85,7 @@ const schema = reactive<FormsSchema[]>([
label: "岗位类别",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 260783972 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -95,7 +96,7 @@ const schema = reactive<FormsSchema[]>([
label: "岗位级别",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 434953981 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -193,7 +194,7 @@ const schema = reactive<FormsSchema[]>([
label: "职务",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 1063530116 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",

View File

@ -39,10 +39,7 @@
<script lang="ts" setup>
import { fractionRuleApi1 } from "@/api/base/server";
import { dicApi } from "@/api/system/dic";
import Template from "@/components/BasicQrcode/_template/template.vue";
import { useDataStore } from "@/store/modules/data";
import { navigateBack, navigateTo, showToast } from "@/utils/uniapp";
import { showToast } from "@/utils/uniapp";
import { cloneDeep, map } from "lodash";
//

View File

@ -47,18 +47,18 @@
</template>
<script lang="ts" setup>
import { dicApi } from "@/api/system/dic";
import { useForm } from "@/components/BasicForm/hooks/useForm";
import { useDataStore } from "@/store/modules/data";
import { navigateBack, navigateTo } from "@/utils/uniapp";
import { cloneDeep, map } from "lodash";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
const schema = reactive<FormsSchema[]>([
{
field: "zcdjId",
label: "职称等级",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 836722710 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -69,7 +69,7 @@ const schema = reactive<FormsSchema[]>([
label: "职称类别",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 912140841 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -112,7 +112,7 @@ const schema = reactive<FormsSchema[]>([
label: "聘用等级",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 1982857463 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",

View File

@ -25,8 +25,9 @@
<script setup lang="ts">
import {navigateBack, navigateTo} from "@/utils/uniapp";
import {useForm} from "@/components/BasicForm/hooks/useForm";
import {dicApi} from "@/api/system/dic";
import {useDataStore} from "@/store/modules/data";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
const { getFile, setFile } = useDataStore();
@ -37,7 +38,7 @@ const [register, { getValue, setValue }] = useForm({
label: "初始学历",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 1914632204 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -60,7 +61,7 @@ const [register, { getValue, setValue }] = useForm({
label: "最后学历",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 1914632204 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -92,7 +93,7 @@ const [register, { getValue, setValue }] = useForm({
component: "BasicPicker",
defaultValue: "无",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 1513282965 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",

View File

@ -15,10 +15,12 @@
import { navigateTo } from "@/utils/uniapp";
import { useForm } from "@/components/BasicForm/hooks/useForm";
import { dicApi, findDicTreeByPidApi } from "@/api/system/dic";
import { findDicTreeByPidApi } from "@/api/system/dic";
import { useDataStore } from "@/store/modules/data";
import { map } from "lodash";
import dayjs from "dayjs";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
const { getFile, setFile } = useDataStore();
const jsjg = ref("");
@ -54,7 +56,7 @@ const [register, { getValue, setValue, setSchema }] = useForm({
label: "性别",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 13001 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -81,7 +83,7 @@ const [register, { getValue, setValue, setSchema }] = useForm({
label: "民族",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 19204295 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -110,7 +112,7 @@ const [register, { getValue, setValue, setSchema }] = useForm({
label: "政治面貌",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 385536488 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -204,7 +206,7 @@ const [register, { getValue, setValue, setSchema }] = useForm({
label: "进入来源",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 2026977361 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -215,7 +217,7 @@ const [register, { getValue, setValue, setSchema }] = useForm({
label: "编制情况",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 290357612 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -226,7 +228,7 @@ const [register, { getValue, setValue, setSchema }] = useForm({
label: "在岗情况",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 810984651 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -254,7 +256,7 @@ const [register, { getValue, setValue, setSchema }] = useForm({
label: "岗位级别",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 260783972 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -265,7 +267,7 @@ const [register, { getValue, setValue, setSchema }] = useForm({
label: "薪级",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 434953981 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",

View File

@ -25,8 +25,9 @@
<script setup lang="ts">
import { navigateBack, navigateTo } from "@/utils/uniapp";
import { useForm } from "@/components/BasicForm/hooks/useForm";
import { dicApi } from "@/api/system/dic";
import { useDataStore } from "@/store/modules/data";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
import {
findAllNjBjTreeApi,
findAllXxXqNjTree,
@ -45,7 +46,7 @@ const [register, { getValue, setValue }] = useForm({
labelPosition: "top",
},
componentProps: {
api: dicApi,
api: findByPid,
multiple: true,
param: { pid: 1063530116 },
rangeKey: "dictionaryValue",
@ -60,7 +61,7 @@ const [register, { getValue, setValue }] = useForm({
labelPosition: "top",
},
componentProps: {
api: dicApi,
api: findByPid,
multiple: true,
param: { pid: 246682695 },
rangeKey: "dictionaryValue",

View File

@ -25,9 +25,10 @@
<script setup lang="ts">
import { navigateBack, navigateTo } from "@/utils/uniapp";
import { useForm } from "@/components/BasicForm/hooks/useForm";
import { dicApi } from "@/api/system/dic";
import { useDataStore } from "@/store/modules/data";
import dayjs from "dayjs";
import { useDicStore } from "@/store/modules/dic";
const { findByPid } = useDicStore();
const { getFile, setFile } = useDataStore();
@ -38,7 +39,7 @@ const [register, { getValue, setValue }] = useForm({
label: "教师资格学段",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 1680570189 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",
@ -49,7 +50,7 @@ const [register, { getValue, setValue }] = useForm({
label: "教师资格学科",
component: "BasicPicker",
componentProps: {
api: dicApi,
api: findByPid,
param: { pid: 1029593616 },
rangeKey: "dictionaryValue",
savaKey: "dictionaryCode",

38
src/store/modules/dic.ts Normal file
View File

@ -0,0 +1,38 @@
import { defineStore } from "pinia";
import { dicApi } from "@/api/system/dic";
interface DicState {
data: any;
}
export const useDicStore = defineStore({
id: "app-dic",
state: (): DicState => ({
// 字典数据
data: {}
}),
getters: {
getData(): any {
return this.data;
}
},
actions: {
setData(data: any) {
this.data = data;
},
async findByPid(params: any): Promise<any> {
if (!params || !params.pid) {
return Promise.resolve();
}
if (!this.data[params.pid]) {
this.data[params.pid] = await dicApi(params);
}
return Promise.resolve(this.data[params.pid]);
},
},
persist: {
enabled: true,
detached: true,
H5Storage: localStorage
},
});

View File

@ -1,6 +1,7 @@
import {defineStore} from "pinia";
import {authenticationApi, loginCode, loginPass, weChatLogin} from "@/api/system/login";
import {AUTH_KEY} from "@/config";
import { useDicStore } from "@/store/modules/dic";
interface UserState {
userdata: any;
@ -104,6 +105,7 @@ export const useUserStore = defineStore({
this.setUser({})
this.setJs({})
this.setAuth([])
useDicStore().setData({});
},
},
persist: {