Explorar el Código

编码分类页面刷新

lipenghui hace 3 días
padre
commit
2608c2940d

+ 41 - 0
src/store/modules/pms/refreshStore.ts

@@ -0,0 +1,41 @@
+// stores/refreshStore.ts
+import { defineStore } from 'pinia';
+
+// 定义回调函数类型
+type RefreshCallback = () => void;
+
+export const useRefreshStore = defineStore('refreshStore', {
+  state: () => ({
+    // 存储页面标识与对应刷新回调的映射
+    callbacks: new Map<string, RefreshCallback>(),
+  }),
+  actions: {
+    /**
+     * 注册页面刷新回调
+     * @param pageKey 页面唯一标识
+     * @param callback 刷新时执行的回调函数
+     */
+    registerCallback(pageKey: string, callback: RefreshCallback): void {
+      this.callbacks.set(pageKey, callback);
+    },
+
+    /**
+     * 移除页面刷新回调
+     * @param pageKey 页面唯一标识
+     */
+    removeCallback(pageKey: string): void {
+      this.callbacks.delete(pageKey);
+    },
+
+    /**
+     * 触发指定页面的刷新回调
+     * @param pageKey 页面唯一标识
+     */
+    triggerRefresh(pageKey: string): void {
+      const callback = this.callbacks.get(pageKey);
+      if (callback) {
+        callback();
+      }
+    },
+  },
+});

+ 10 - 1
src/views/pms/device/IotDeviceForm.vue

@@ -396,6 +396,7 @@ import { useTagsViewStore } from '@/store/modules/tagsView'
 import {DeviceAttrModelApi} from "@/api/pms/deviceattrmodel";
 import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
 import {IotYfClassifyApi} from "@/api/pms/yfclass";
+import { useRefreshStore } from '@/store/modules/pms/refreshStore';
 
 /** 设备台账 表单 */
 defineOptions({ name: 'DeviceDetailAdd' })
@@ -408,7 +409,7 @@ const username = ref('')
 const deptList = ref<Tree[]>([]) // 树形结构
 const productClassifyList = ref<Tree[]>([]) // 树形结构
 const { delView } = useTagsViewStore() // 视图操作
-const { params, name } = useRoute() // 查询参数
+const { params, name,query } = useRoute() // 查询参数
 const { currentRoute, push } = useRouter()
 const { wsCache } = useCache()
 const id = params.id
@@ -425,6 +426,8 @@ const brandLabel = ref('') // 表单的类型:create - 新增;update - 修
 const zzLabel = ref('') // 表单的类型:create - 新增;update - 修改
 const supplierLabel = ref('') // 表单的类型:create - 新增;update - 修改
 const yfclasses = ref([])
+const refreshStore = useRefreshStore();
+
 const formData = ref({
   id: undefined,
   yfClass: undefined,
@@ -637,6 +640,12 @@ const submitForm = async () => {
     dialogVisible.value = false
     // 发送操作成功的事件
     //emit('success')
+    const sourcePage = query.source as string;
+
+    // 如果有来源页面标识,触发原页面的刷新
+    if (sourcePage) {
+      refreshStore.triggerRefresh(sourcePage);
+    }
     close()
   } finally {
     formLoading.value = false

+ 9 - 2
src/views/pms/device/IotDeviceFormAdd.vue

@@ -388,7 +388,7 @@ import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
 import { useTagsViewStore } from '@/store/modules/tagsView'
 import {DeviceAttrModelApi} from "@/api/pms/deviceattrmodel";
 import {IotYfClassifyApi} from "@/api/pms/yfclass";
-
+import { useRefreshStore } from '@/store/modules/pms/refreshStore';
 
 /** 设备台账 表单 */
 defineOptions({ name: 'DeviceDetailAddd' })
@@ -400,7 +400,7 @@ const qtIsExpanded = ref(true) // 控制表单是否展开的变量
 const deptList = ref<Tree[]>([]) // 树形结构
 const productClassifyList = ref<Tree[]>([]) // 树形结构
 const { delView } = useTagsViewStore() // 视图操作
-const { params, name } = useRoute() // 查询参数
+const { params, name, query } = useRoute() // 查询参数
 const { currentRoute, push } = useRouter()
 
 const id = params.id
@@ -417,6 +417,7 @@ const brandLabel = ref('') // 表单的类型:create - 新增;update - 修
 const zzLabel = ref('') // 表单的类型:create - 新增;update - 修改
 const supplierLabel = ref('') // 表单的类型:create - 新增;update - 修改
 const yfclasses = ref([])
+const refreshStore = useRefreshStore();
 const formData = ref({
   id: undefined,
   deviceCode: undefined,
@@ -626,6 +627,12 @@ const submitForm = async () => {
     dialogVisible.value = false
     // 发送操作成功的事件
     //emit('success')
+    const sourcePage = query.source as string;
+
+    // 如果有来源页面标识,触发原页面的刷新
+    if (sourcePage) {
+      refreshStore.triggerRefresh(sourcePage);
+    }
     close()
   } finally {
     formLoading.value = false

+ 7 - 3
src/views/pms/device/index.vue

@@ -215,6 +215,7 @@ import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
 import {buildSortingField} from "@/utils";
 import {defaultProps, handleTree} from "@/utils/tree";
 import * as ProductClassifyApi from "@/api/pms/productclassify";
+import { useRefreshStore } from '@/store/modules/pms/refreshStore';
 
 /** 设备台账 列表 */
 defineOptions({ name: 'IotDevicePms' })
@@ -223,6 +224,7 @@ const message = useMessage() // 消息弹窗
 const { t } = useI18n() // 国际化
 const { push } = useRouter() // 路由跳转
 
+const refreshStore = useRefreshStore();
 const loading = ref(true) // 列表的加载中
 const ifShow = ref(false)
 const isDetail = ref(false) // 是否查看详情
@@ -322,14 +324,14 @@ const formRef = ref()
 const openForm = (type: string, id?: number,deptId?:number) => {
   //修改
   if (typeof id === 'number') {
-    push({ name: 'DeviceDetailEdit', params: { type,id } })
+    push({ name: 'DeviceDetailEdit', params: { type,id }, query:{source:'devicerouter'} })
     return
   }
   // 新增
   if (deptId) {
-    push({ name: 'DeviceDetailAdd', params: {type,deptId} })
+    push({ name: 'DeviceDetailAdd', params: {type,deptId}, query:{source:'devicerouter'} })
   }else {
-    push({ name: 'DeviceDetailAddd', params: {} })
+    push({ name: 'DeviceDetailAddd', params: {} ,query:{source:'devicerouter'}})
   }
 }
 
@@ -380,6 +382,8 @@ onMounted(async () => {
   }
   queryParams.sortingFields.push(sort);
   await getList()
+  refreshStore.registerCallback('devicerouter', getList);
+
 })
 </script>
 <style scoped></style>