ソースを参照

修复PC端问卷下拉框加载

Developer 1 ヶ月 前
親
コミット
0f82206064

BIN
dist.zip


+ 4 - 4
src/store_v3/modules/agent.js

@@ -56,10 +56,10 @@ export const useAgentStore = defineStore('agent', () => {
         });
     };
 
-    const questionnaireList = ref([]);
-    const questionnaireMap = ref(new Map());
-    const getQuestionnaireData = () => {
-        getQuestionnaireList({page:1,limit:-1}).then((res) => {
+    const questionnaireList = ref([]);
+    const questionnaireMap = ref(new Map());
+    const getQuestionnaireData = () => {
+        return getQuestionnaireList({page:1,limit:-1}).then((res) => {
             questionnaireList.value = res.data.list;
             const map = new Map();
             questionnaireList.value.forEach((supplier) => {

+ 7 - 6
src/views/modules/agent/questionnaire.vue

@@ -187,7 +187,7 @@
         updateQuestionnairePublish
     } from "@/api/agent/index.js";
     const { proxy } = getCurrentInstance();
-    useAgentStore().getQuestionnaireData();
+    const agentStore = useAgentStore()
     
     const questionnaireList = ref([])
     const queryParams = ref({
@@ -392,10 +392,11 @@
         getList();
     }
 
-    onMounted(()=>{
-        questionnaireList.value = useAgentStore().questionnaireList?.filter(l=>l.type>=3) || []
-        getList()
-    })
+    onMounted(async ()=>{
+        await agentStore.getQuestionnaireData()
+        questionnaireList.value = agentStore.questionnaireList || []
+        getList()
+    })
 </script>
 
 <style scoped lang="scss">
@@ -787,4 +788,4 @@
             }
         }
     }
-</style>
+</style>

+ 7 - 6
src/views/modules/agent/report.vue

@@ -102,9 +102,9 @@
         getPersonQueList,
         sendReportUsers
      } from "@/api/agent/index.js";
-    import {useAgentStore} from "@/store_v3/modules/agent";
-    import useCommonStore from "@/store_v3/modules/common";
-    useAgentStore().getQuestionnaireData();
+    import {useAgentStore} from "@/store_v3/modules/agent";
+    import useCommonStore from "@/store_v3/modules/common";
+    const agentStore = useAgentStore()
     useAgentStore().getTeamData();
 
     const questionnaireList = ref([])
@@ -305,8 +305,9 @@
         })
     }
 
-    onMounted(async ()=>{
-        questionnaireList.value = useAgentStore().questionnaireList?.filter(l=>l.type>=3) || []
+    onMounted(async ()=>{
+        await agentStore.getQuestionnaireData()
+        questionnaireList.value = agentStore.questionnaireList || []
         let type = proxy.$route.query?.type;
         let relationId = proxy.$route.query?.relationId;
         if(!type) return getTeamList()
@@ -430,4 +431,4 @@
             }
         }
     }
-</style>
+</style>

+ 26 - 0
tests/unit/questionnaireSelector.spec.js

@@ -0,0 +1,26 @@
+const fs = require('fs')
+const path = require('path')
+
+const storeSource = fs.readFileSync(
+  path.resolve(__dirname, '../../src/store_v3/modules/agent.js'),
+  'utf8'
+)
+const questionnaireSource = fs.readFileSync(
+  path.resolve(__dirname, '../../src/views/modules/agent/questionnaire.vue'),
+  'utf8'
+)
+const reportSource = fs.readFileSync(
+  path.resolve(__dirname, '../../src/views/modules/agent/report.vue'),
+  'utf8'
+)
+
+test('questionnaire data loading is awaitable', () => {
+  expect(storeSource).toMatch(/const getQuestionnaireData\s*=\s*\(\)\s*=>\s*\{\s*return getQuestionnaireList/s)
+})
+
+test('questionnaire and report selectors wait for and expose all questionnaires', () => {
+  expect(questionnaireSource).toContain('await agentStore.getQuestionnaireData()')
+  expect(reportSource).toContain('await agentStore.getQuestionnaireData()')
+  expect(questionnaireSource).not.toContain('.filter(l=>l.type>=3)')
+  expect(reportSource).not.toContain('.filter(l=>l.type>=3)')
+})