ソースを参照

style改then为finally,其余细节小改

kuanghua liu 2 年 前
コミット
72f4feb576

+ 3 - 6
src/views/cameras/algo-management/algoManagement.vue

@@ -34,7 +34,7 @@
             :total="20"
             v-model:current-page="curPage"
             @current-change="changePage"
-            :page-size="10"
+            :page-size="pageSize"
           />
         </div>
       </div>
@@ -91,10 +91,8 @@
 </template>
 <script lang="ts" setup>
   import { onMounted, ref, onUnmounted, reactive, watchEffect } from 'vue';
-  import { cloneDeep } from 'lodash-es';
   import { PageWrapper } from '../../../components/Page';
-  import 'video.js/dist/video-js.css';
-  import useAlgo from './use-algoData';
+  import useAlgo from './useAlgoData';
   import { Search } from '@element-plus/icons-vue';
   import type { FormInstance, FormRules } from 'element-plus';
 
@@ -115,7 +113,6 @@
   //将后端拉到的数据存到algoListUse数组中进行使用
   //刷新时从后端拉一次算法数组
   onMounted(() => {
-    pageSize.value = 12;
     getAlgoDatas();
   });
 
@@ -192,7 +189,7 @@
         // console.log('algoId', algoId.value);
         // console.log('pushStatement', pushStatement.value);
         // console.log('pushLinkPrompt', pushLinkPrompt.value);
-        modifyAlgoDatas().then(() => {
+        modifyAlgoDatas().finally(() => {
           isSending.value = false;
         });
       } else {

+ 54 - 0
src/views/cameras/algo-management/useAlgoData.ts

@@ -0,0 +1,54 @@
+import { getAlgoInfo, searchAlgoInfo, algoInfoModify } from '@/api/algo/algo';
+import { ref } from 'vue';
+import { ElMessage } from 'element-plus';
+
+export function useAlgo() {
+  const algoList = ref([]);
+  const page = ref(1);
+  const pageSize = ref(12);
+  const keyWord = ref('');
+
+  const algoId = ref(0);
+  const pushLinkPrompt = ref('');
+  const pushStatement = ref('');
+
+  const getAlgoDatas = () => {
+    return getAlgoInfo(page.value, pageSize.value).then((res) => {
+      algoList.value = res.records;
+    });
+  };
+
+  const searchAlgoDatas = () => {
+    return searchAlgoInfo(page.value, keyWord.value).then((res) => {
+      algoList.value = res.records;
+    });
+  };
+
+  const modifyAlgoDatas = () => {
+    return algoInfoModify(algoId.value, pushLinkPrompt.value, pushStatement.value)
+      .then(function () {
+        ElMessage({
+          message: '算法数据保存成功',
+          type: 'success',
+        });
+      })
+      .catch(function () {
+        ElMessage.error('算法数据保存失败');
+      });
+  };
+
+  return {
+    algoList,
+    page,
+    pageSize,
+    keyWord,
+    getAlgoDatas,
+    searchAlgoDatas,
+    algoId,
+    pushLinkPrompt,
+    pushStatement,
+    modifyAlgoDatas,
+  };
+}
+
+export default useAlgo;