ソースを参照

feat: 热更新

Ritchie 1 年間 前
コミット
cb822909dd
2 ファイル変更68 行追加11 行削除
  1. 5 0
      src/service/hotUpdate/index.js
  2. 63 11
      src/views/hotUpdate/index.vue

+ 5 - 0
src/service/hotUpdate/index.js

@@ -0,0 +1,5 @@
+import axios from '@/utils/axios';
+
+export function postPatchInfo(patchInfoCheck) {
+    return axios.post(`/SZWL-SERVER/tHotUpdate/postPatchInfo`, patchInfoCheck);
+}

+ 63 - 11
src/views/hotUpdate/index.vue

@@ -11,7 +11,7 @@
                 <!-- 补丁状态:停止/发布 -->
                 <van-field name="radio" label="补丁状态:">
                     <template #input>
-                        <van-radio-group v-model="checked" direction="horizontal" shape="dot">
+                        <van-radio-group v-model="patchStatus" direction="horizontal" shape="dot">
                             <van-radio name="0">停止</van-radio>
                             <van-radio name="1">发布</van-radio>
                         </van-radio-group>
@@ -21,7 +21,7 @@
                 <!-- 补丁目标区域:国内/海外 -->
                 <van-field name="checkboxGroup" label="推送区域:">
                     <template #input>
-                        <van-checkbox-group v-model="targetAreas" direction="horizontal">
+                        <van-checkbox-group v-model="targetAreasBlock" direction="horizontal">
                             <van-checkbox name="1" shape="square">国内</van-checkbox>
                             <van-checkbox name="2" shape="square">海外</van-checkbox>
                         </van-checkbox-group>
@@ -33,9 +33,9 @@
                 <!-- 选填clientId,填了就是灰度更新,不填就是全量更新 -->
                 <van-field v-model="clientId" rows="2" autosize name="clientId" label="设备编号:" type="textarea" clearable
                     placeholder="选填clientId,使用','隔开" :disabled="hasTargetAreas" maxlength="230" show-word-limit />
-                <!-- 补丁更新内容updateInfo -->
-                <van-field v-model="updateInfo" name="updateInfo" label="更新内容:" placeholder="补丁更新内容(选填)" clearable rows="2"
-                    autosize left-icon="edit" maxlength="50" show-word-limit type="textarea" />
+                <!-- 补丁更新内容note -->
+                <van-field v-model="note" name="note" label="更新内容:" placeholder="补丁更新内容(选填)" clearable rows="2"
+                    autosize maxlength="50" show-word-limit type="textarea" />
 
             </van-cell-group>
             <br>
@@ -50,22 +50,25 @@
 
 <script>
 import sHeader from "@/components/SimpleHeader";
+import { postPatchInfo } from "../../service/hotUpdate/index";
 import { watch } from "vue";
 import { ref } from "vue";
+import { showFailToast, showToast } from "vant";
 
 export default {
     components: { sHeader },
     setup() {
 
         const patchVersion = ref(''); // 版本号
-        const checked = ref('0'); // 补丁状态: 停止('0') 发布('1')
-        const targetAreas = ref([]); // 目标区域
+        const patchStatus = ref('0'); // 补丁状态: 停止('0') 发布('1')
+        const targetAreasBlock = ref([]); // 目标区域数组
+        const targetAreas = ref(''); // 目标区域
         const patchLink = ref(''); // 补丁外链
         const clientId = ref(''); // 设备编号
-        const updateInfo = ref(''); // 更新内容
+        const note = ref(''); // 更新内容
         const hasTargetAreas = ref(false); // 是否有目标区域
 
-        watch(targetAreas, (newVal) => {
+        watch(targetAreasBlock, (newVal) => {
             hasTargetAreas.value = newVal.length > 0;
             if (hasTargetAreas.value) {
                 clientId.value = ''; // 清空设备编号
@@ -74,16 +77,65 @@ export default {
 
         // 点击提交
         const onSubmit = async () => {
+            if(targetAreasBlock.value.length === 0) {
+                targetAreas.value = '0';
+            } else if(targetAreasBlock.value.length === 1){
+                targetAreas.value = targetAreasBlock.value[0];
+            } else {
+                targetAreas.value = '3';
+            }
+            console.log("targetAreas >>> ", targetAreas.value);
+            const patchInfoCheck = {
+                patchVersion: patchVersion.value,
+                patchStatus: patchStatus.value,
+                targetAreas: targetAreas.value,
+                patchLink: patchLink.value,
+                clientId: clientId.value,
+                note: note.value
+            }
+            try {
+                const data = await postPatchInfo(patchInfoCheck);
+                if (data.code === '00000') {
+                    showToast('提交成功', 'success');
+                } else {
+                    showFailToast('提交失败');
+                }
+                // 提交成功后重置表单
+                resetForm();
+            } catch (error) {
+                // 处理请求出错的情况
+                showFailToast(error.response.data.error);
+            }
 
         }
+        const formData = ref({
+            patchVersion: patchVersion.value,
+            patchStatus: patchStatus.value,
+            targetAreas: targetAreas.value,
+            patchLink: patchLink.value,
+            clientId: clientId.value,
+            note: note.value
+        })
+        // 重置表单的方法
+        const resetForm = () => {
+            formData.value = {
+                patchVersion: '',
+                patchStatus: '',
+                targetAreas: '',
+                patchLink: '',
+                clientId: '',
+                note: ''
+            };
+        };
         return {
             onSubmit,
             patchVersion,
-            checked,
+            patchStatus,
+            targetAreasBlock,
             targetAreas,
             patchLink,
             clientId,
-            updateInfo,
+            note,
             hasTargetAreas
         }
     }