From e37e45cfe1123928dba5d9c5a427b0ee497b7ad6 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 23 八月 2022 03:21:32 +0800
Subject: [PATCH] 修复算法配置的字段内容

---
 src/views/hashrate/AlgManage/index.vue |  487 ++++++++++++++++++++++++++---------------------------
 1 files changed, 239 insertions(+), 248 deletions(-)

diff --git a/src/views/hashrate/AlgManage/index.vue b/src/views/hashrate/AlgManage/index.vue
index f5c226d..5b355d5 100644
--- a/src/views/hashrate/AlgManage/index.vue
+++ b/src/views/hashrate/AlgManage/index.vue
@@ -6,19 +6,19 @@
 
       <!-- 鏀惰垂绠楁硶鍒楄〃 -->
       <div class="label">鏀惰垂绠楁硶</div>
-      <div class="payList">
+      <div class="payList scroll">
         <div class="algCard" v-for="(item, index) in payAlg" :key="index">
-          <img :src="item.img" alt="" draggable="false" />
-          <div class="name">{{ item.name }}</div>
-          <span class="button pay">璐拱</span>
+          <img :src="item.logoUrl" alt="" draggable="false" />
+          <div class="name">{{ item.productName }}</div>
+          <span class="button pay" @click="toDetail(item.id)">璐拱</span>
         </div>
       </div>
 
       <!-- 鍏嶈垂绠楁硶鍒楄〃 -->
-      <div class="label">
-        鍏嶈垂绠楁硶 <span class="des">浠庢澶勬嫋鎷界畻娉曞浘鏍囧畨瑁呭埌璁惧</span>
+      <div class="label freeLabel">
+        鏈湴绠楁硶 <span class="des">浠庢澶勬嫋鎷界畻娉曞浘鏍囧畨瑁呭埌璁惧</span>
       </div>
-      <div class="freeList">
+      <div class="freeList scroll">
         <div
           class="algCard"
           v-for="(item, index) in freeAlg"
@@ -26,13 +26,13 @@
           @dragend="dragAlg = null"
         >
           <img
-            :src="item.img"
+            :src="item.logoUrl"
             alt=""
             draggable="true"
             @dragstart="dragStart(item)"
           />
-          <div class="name">{{ item.name }}</div>
-          <span class="button detail">鏌ョ湅璇︽儏</span>
+          <div class="name">{{ item.productName }}</div>
+          <span class="button detail" @click="toDetail(item.id)">鏌ョ湅璇︽儏</span>
         </div>
       </div>
     </div>
@@ -40,33 +40,38 @@
     <!-- 鍙充晶绠楁硶绠$悊 -->
     <div class="rightList">
       <div class="title">绠楁硶绠$悊</div>
-      <div class="button update">鍏ㄩ儴鏇存柊</div>
+      <div class="button update" @click="updateAll">鍏ㄩ儴鏇存柊</div>
 
       <!-- 璁惧 -->
       <div class="equipment" v-for="(item, index) in equipmentArr" :key="index">
-        <div class="name">{{ item.name }}</div>
+        <div class="name">{{ item.devName }}</div>
         <!-- 绠楁硶鍒楄〃 -->
         <div class="algList">
           <!-- 绠楁硶card -->
           <Card
-            v-for="(alg, index) in item.algs"
+            v-for="(alg, index) in item.sdkList1"
             :key="index"
             :alg="alg"
+            :devId="item.devId"
+            @unInstall="item.sdkList1.splice(index, 1)"
           ></Card>
           <!-- 鎷栨嫿瀛樻斁box -->
           <div
             class="dropBox"
             v-if="dragAlg"
             @dragover="dragover($event)"
-            @drop="drop(item.algs)"
+            @drop="drop(item.sdkList1, item.devId)"
           >
             璇锋嫋鍔ㄥ埌姝ゅ
           </div>
           <!-- 绌虹畻娉曟儏鍐� -->
-          <div class="empty" v-if="item.algs.length === 0 && !dragAlg">
-            <img src="/images/hashrate/绠楁硶绠$悊绌洪〉闈�.png" alt="" />
+          <div
+            class="empty"
+            v-if="item.sdkList1 && item.sdkList1.length === 0 && !dragAlg"
+          >
+            <img src="/images/hashrate/sdkEmpty.png" alt="" />
             <div class="des">
-              鏆傛湭瀹夎绠楁硶锛屼粠宸︿晶绠楁硶涓績鎷栧埌绠楁硶鍒版澶勶紝鍗冲彲瀹夎
+              鏆傛湭瀹夎绠楁硶锛屼粠宸︿晶绠楁硶涓績绠楁硶鍒版澶勶紝鍗冲彲瀹夎
             </div>
           </div>
         </div>
@@ -78,16 +83,19 @@
       <div class="title">閰嶇疆鎻愮ず</div>
       <div class="control">
         <div class="label">鍚敤绠楁硶浠撶鐞�</div>
-        <el-switch v-model="setting" active-color="#D4E3FA" :width="56">
+        <el-switch v-model="setting" active-color="#D4E3FA" :width="44">
         </el-switch>
       </div>
       <div class="des">鍚敤鍚庣畻娉曠鐞嗛〉闈㈤厤缃敓鏁堬紝鍚﹀垯涓嶇敓鏁�</div>
       <div class="btns">
-        <div class="cancel button" @click="closeSettingBox">鍙栨秷</div>
         <div class="confirm button" @click="closeSettingBox">纭畾</div>
       </div>
-      <span class="iconfont close" @click="closeSettingBox">&#xe60f;</span>
     </div>
+
+    <div class="setBtn iconfont" @click="showSettingBox = true">
+      &#xe652; 閰嶇疆鎻愮ず
+    </div>
+
     <!-- 閬僵灞� -->
     <div class="mask" v-if="showSettingBox"></div>
   </div>
@@ -95,208 +103,102 @@
 
 <script>
 import Card from "./components/AlgCard";
+
+import {
+  getAllCenterProduct,
+  getSdkConfigInfo,
+  saveSdkConfig,
+  findAllSdk,
+  downloadOrUpgrade,
+  unInstallAll,
+} from "@/api/algorithm";
 export default {
   components: {
     Card,
   },
+  created() {
+    this.getConfig();
+    this.getProduct();
+    this.getEquipment();
+  },
   data() {
     return {
-      showSettingBox: true,
-      setting: true,
-      payAlg: [
-        {
-          img: "/images/index/1浠板崸妫�娴�.png",
-          name: "浠板崸妫�娴�",
-        },
-        {
-          img: "/images/index/1浠板崸妫�娴�.png",
-          name: "浠板崸妫�娴�",
-        },
-        {
-          img: "/images/index/1浠板崸妫�娴�.png",
-          name: "浠板崸妫�娴�",
-        },
-        {
-          img: "/images/index/1浠板崸妫�娴�.png",
-          name: "浠板崸妫�娴�",
-        },
-        {
-          img: "/images/index/1浠板崸妫�娴�.png",
-          name: "浠板崸妫�娴�",
-        },
-        {
-          img: "/images/index/1浠板崸妫�娴�.png",
-          name: "浠板崸妫�娴�",
-        },
-        {
-          img: "/images/index/1浠板崸妫�娴�.png",
-          name: "浠板崸妫�娴�",
-        },
-        {
-          img: "/images/index/1浠板崸妫�娴�.png",
-          name: "浠板崸妫�娴�",
-        },
-      ],
-      freeAlg: [
-        {
-          img: "/images/index/1浠板崸妫�娴�.png",
-          name: "浠板崸妫�娴�",
-        },
-        {
-          img: "/images/index/11婊炵暀.png",
-          name: "婊炵暀",
-        },
-        {
-          img: "/images/index/15鎴村彛缃�.png",
-          name: "鎴村彛缃�",
-        },
-      ],
-      equipmentArr: [
-        {
-          name: "璁惧1",
-          algs: [
-            {
-              img: "/images/index/1浠板崸妫�娴�.png",
-              name: "浠板崸妫�娴�",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/11婊炵暀.png",
-              name: "婊炵暀",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/15鎴村彛缃�.png",
-              name: "鎴村彛缃�",
-              version: "v1.0.0",
-              newVersion: "v1.0.2",
-              hasNewVersion: true,
-            },
-            {
-              img: "/images/index/1浠板崸妫�娴�.png",
-              name: "浠板崸妫�娴�",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/11婊炵暀.png",
-              name: "婊炵暀",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/15鎴村彛缃�.png",
-              name: "鎴村彛缃�",
-              version: "v1.0.0",
-              newVersion: "v1.0.2",
-              hasNewVersion: true,
-            },
-            {
-              img: "/images/index/1浠板崸妫�娴�.png",
-              name: "浠板崸妫�娴�",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/11婊炵暀.png",
-              name: "婊炵暀",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/15鎴村彛缃�.png",
-              name: "鎴村彛缃�",
-              version: "v1.0.0",
-              newVersion: "v1.0.2",
-              hasNewVersion: true,
-            },
-            {
-              img: "/images/index/1浠板崸妫�娴�.png",
-              name: "浠板崸妫�娴�",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/11婊炵暀.png",
-              name: "婊炵暀",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/15鎴村彛缃�.png",
-              name: "鎴村彛缃�",
-              version: "v1.0.0",
-              newVersion: "v1.0.2",
-              hasNewVersion: true,
-            },
-            {
-              img: "/images/index/1浠板崸妫�娴�.png",
-              name: "浠板崸妫�娴�",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/11婊炵暀.png",
-              name: "婊炵暀",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/15鎴村彛缃�.png",
-              name: "鎴村彛缃�",
-              version: "v1.0.0",
-              newVersion: "v1.0.2",
-              hasNewVersion: true,
-            },
-          ],
-        },
-        {
-          name: "璁惧2",
-          algs: [
-            {
-              img: "/images/index/1浠板崸妫�娴�.png",
-              name: "浠板崸妫�娴�",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/11婊炵暀.png",
-              name: "婊炵暀",
-              version: "v1.0.0",
-              newVersion: "v1.0.0",
-              hasNewVersion: false,
-            },
-            {
-              img: "/images/index/15鎴村彛缃�.png",
-              name: "鎴村彛缃�",
-              version: "v1.0.0",
-              newVersion: "v1.0.2",
-              hasNewVersion: true,
-            },
-          ],
-        },
-        {
-          name: "璁惧3",
-          algs: [],
-        },
-      ],
+      showSettingBox: false,
+      setting: false,
+      payAlg: [],
+      freeAlg: [],
+      equipmentArr: [],
       dragAlg: null,
     };
   },
   methods: {
+    //鑾峰彇绠楁硶绠$悊璁剧疆
+    async getConfig() {
+      let user = JSON.parse(sessionStorage.getItem("userInfo"));
+      const res = await getSdkConfigInfo({
+        userId: user.id,
+        variable: "sdkManageConfig",
+      });
+      if (res && res.success) {
+        if (!res.data.value || res.data.value == "off") {
+          this.showSettingBox = true;
+        } else {
+          this.setting = res.data.value === "on" ? true : false;
+        }
+      }
+    },
+
+    //鑾峰彇宸︿晶浜у搧鍒楄〃
+    async getProduct() {
+      const res = await getAllCenterProduct({
+        page: 1,
+        size: 1000000,
+        inputText: "",
+        productType: 3,
+        publishStatus: 1,
+      });
+
+      if (res && res.success) {
+        res.data.list.forEach((item) => {
+          if (item.productName == "瓒翠紡") {
+            console.log(item);
+          }
+
+          if (
+            item.logoUrl.indexOf("http://apps.smartai.com/httpImage/") === -1 &&
+            item.logoUrl.indexOf("/files") != 0
+          ) {
+            item.logoUrl = "/httpImage/" + item.logoUrl;
+          }
+
+          if (item.priceBase === 0) {
+            this.freeAlg.push(item);
+          } else {
+            this.payAlg.push(item);
+          }
+        });
+      }
+    },
+
+    //鑾峰彇鍙充晶璁惧鍒楄〃
+    async getEquipment() {
+      const res = await findAllSdk();
+      if (res && res.success) {
+        this.equipmentArr = [];
+        res.data.forEach((item, index) => {
+          if (item.sdkList) {
+            let sdkList1 = [];
+            item.sdkList.forEach((sdk) => {
+              if (sdk.installed) {
+                sdkList1.push(sdk);
+              }
+            });
+            item.sdkList1 = sdkList1;
+            this.equipmentArr.push(item);
+          }
+        });
+      }
+    },
     //鎷栨嫿寮�濮�
     dragStart(alg) {
       this.dragAlg = alg;
@@ -306,18 +208,84 @@
     dragover(e) {
       e.preventDefault();
     },
-    drop(algArr) {
+    async drop(algArr, devId) {
       algArr.push({
-        img: this.dragAlg.img,
-        name: this.dragAlg.name,
-        version: "v1.0.0",
-        newVersion: "v1.0.0",
-        hasNewVersion: false,
+        iconBlob: this.dragAlg.logoUrl,
+        sdk_name: this.dragAlg.productName,
       });
+
+      try {
+        const res = await downloadOrUpgrade({
+          nodeId: devId,
+          path: this.dragAlg.productBaseId,
+          userId: JSON.parse(sessionStorage.getItem("userInfo")).id,
+          inputText: this.dragAlg.productName,
+        });
+        if (res && res.success) {
+          this.$notify({
+            type: "success",
+            message: "鎿嶄綔鎴愬姛,璇风◢鍚�",
+          });
+        }
+      } catch (err) {
+        algArr.pop();
+      }
+
       this.dragAlg = null;
     },
-    closeSettingBox() {
-      this.showSettingBox = false;
+    async closeSettingBox() {
+      let user = JSON.parse(sessionStorage.getItem("userInfo"));
+      const res = await saveSdkConfig({
+        userId: user.id,
+        variable: "sdkManageConfig",
+        value: this.setting ? "on" : "off",
+      }).catch(() => {
+        this.$notify.error({
+          message: "閰嶇疆澶辫触",
+        });
+      });
+      if (res && res.success) {
+        this.$notify.success({
+          message: "閰嶇疆鎴愬姛",
+        });
+        if (this.setting) {
+          this.showSettingBox = false;
+        }
+      }
+    },
+    async updateAll() {
+      let devArr = [];
+      this.equipmentArr.forEach((dev) => {
+        let devObj = {};
+        let sdkIds = [];
+        devObj.devId = dev.devId;
+        dev.sdkList1.forEach((sdk) => {
+          if (sdk.isUpgrade) {
+            sdkIds.push(sdk.id);
+          }
+        });
+        devObj.sdkIds = sdkIds;
+        devArr.push(devObj);
+      });
+
+      const res = await unInstallAll({
+        userId: JSON.parse(sessionStorage.getItem("userInfo")).id,
+        devSdkIds: devArr,
+      });
+      if (res && res.success) {
+        this.$notify({
+          type: "success",
+          message: res.msg,
+        });
+      }
+    },
+    toDetail(id) {
+      this.$router.push({
+        path: "/productDetail",
+        query: {
+          id: id,
+        },
+      });
     },
   },
 };
@@ -327,6 +295,20 @@
 .AlgManage {
   display: flex;
   margin-bottom: 60px;
+
+  .setBtn {
+    position: absolute;
+    top: 161px;
+    right: 44px;
+    width: 112px;
+    height: 32px;
+    line-height: 32px;
+    border-radius: 3px;
+    border: 1px solid #0064ff;
+    color: #0064ff;
+    text-align: center;
+    cursor: pointer;
+  }
 
   .leftMenu {
     align-self: stretch;
@@ -358,8 +340,14 @@
       }
     }
 
+    .freeLabel {
+      margin-top: 20px;
+    }
+
     .payList,
     .freeList {
+      max-height: 320px;
+      overflow: auto;
       display: flex;
       flex-wrap: wrap;
 
@@ -367,7 +355,7 @@
         box-sizing: border-box;
         margin-right: 10px;
         margin-bottom: 16px;
-        width: 95px;
+        width: 90px;
         height: 144px;
         border: 1px solid #e9ebee;
         border-radius: 5px;
@@ -434,15 +422,15 @@
 
     .update {
       position: absolute;
-      top: 20px;
-      right: 20px;
-      width: 140px;
-      height: 40px;
+      top: 6px;
+      right: 165px;
+      width: 112px;
+      height: 32px;
       background: #0065ff;
       color: #fff;
-      font-size: 14px;
+      /* font-size: 15px; */
       font-weight: 700;
-      line-height: 40px;
+      line-height: 33px;
       text-align: center;
     }
 
@@ -490,10 +478,10 @@
     z-index: 2;
     top: 50%;
     left: 50%;
-    margin-top: -112px;
+    margin-top: -108px;
     margin-left: -180px;
     width: 360px;
-    height: 224px;
+    height: 216px;
     background-color: #fff;
 
     .title {
@@ -519,20 +507,30 @@
 
       .el-switch ::v-deep {
         height: 24px;
-
         .el-switch__core {
-          border-radius: 16px;
           height: 24px;
-
-          &::after {
-            top: 3px;
-            background: #0065ff;
-          }
+          border-radius: 16px;
+        }
+        .el-switch__core::after {
+          width: 20px;
+          height: 20px;
+          background-color: #999999;
+        }
+      }
+      .el-switch.is-checked ::v-deep {
+        .el-switch__core {
+          background-color: #d4e3fa;
+          border-color: #d4e3fa;
+        }
+        .el-switch__core::after {
+          margin-left: -22px;
+          background-color: #0065ff;
         }
       }
     }
 
     .des {
+      margin-top: 10px;
       margin-left: 20px;
       font-size: 12px;
       color: #0065ff;
@@ -544,22 +542,15 @@
       bottom: 20px;
       right: 20px;
       text-align: center;
-      line-height: 40px;
-
-      .cancel {
-        margin-right: 10px;
-        width: 104px;
-        height: 40px;
-        border: 1px solid #0065ff;
-        color: #0065ff;
-      }
+      line-height: 32px;
 
       .confirm {
-        width: 104px;
-        height: 40px;
+        width: 60px;
+        height: 32px;
         border: 1px solid #0065ff;
         background-color: #0065ff;
         color: #fff;
+        border-radius: 3px;
       }
     }
 
@@ -575,7 +566,7 @@
 
   .mask {
     position: absolute;
-    top: 0;
+    top: 62px;
     left: 0;
     right: 0;
     bottom: 0;

--
Gitblit v1.8.0