hanbaoshan
2021-02-25 77ea6f71e7532e89b974bcb65ce5a6b67a680ddb
src/pages/ai/index/App.vue
@@ -19,7 +19,7 @@
              @tab-click="handleTabClick"
              style="height: calc(100% - 20px);"
            >
              <el-tab-pane label="已安装" name="myAlgorithm">
              <el-tab-pane label="已激活" name="myAlgorithm">
                <div class="width-new-line task-list" v-show="activeName === 'myAlgorithm'">
                  <p class="src-title">算法软件</p>
                  <div class="flex-list">
@@ -74,25 +74,20 @@
                            :element-loading-text="item.progressMsg"
                            element-loading-background="rgba(0,0,0,.8)"
                          >
                            <!-- <div class="mask flex-center">
                              <div class="info-onmask">
                                <div>当前版本:{{item.version}}</div>
                              </div>
                            </div>-->
                            <i class="iconfont iconupdate" v-if="item.isUpgrade"></i>
                            <div class="mask" v-if="!item.isDefault || item.isUpgrade">
                              <div class="info-onmask">
                              <div class="left-top">
                                <div>当前版本:{{item.version}}</div>
                                <div v-if="item.remoteVersion">最新版本:{{item.remoteVersion}}</div>
                              </div>
                              <div class="info-onmask" @click="checkDetail(item)">查看详情</div>
                              <div class="mask-btn">
                                <!-- <el-button
                                  v-if="!item.isDefault"
                                  @click="unLoad(item)"
                                <el-button
                                  @click="unLoadSdk(item)"
                                  type="primary"
                                  size="small"
                                  class="bot-btn"
                                >卸载</el-button>-->
                                >卸载</el-button>
                                <el-button
                                  v-if="item.isUpgrade"
                                  @click="donwload(item)"
@@ -176,11 +171,12 @@
                            element-loading-background="rgba(0,0,0,.8)"
                          >
                            <i class="iconfont iconupdate" v-if="item.isUpgrade"></i>
                            <div class="mask" v-if="!item.isDefault || item.isUpgrade">
                              <div class="info-onmask">
                            <div class="mask">
                              <div class="left-top">
                                <div>当前版本:{{item.version}}</div>
                                <div v-if="item.remoteVersion">最新版本:{{item.remoteVersion}}</div>
                              </div>
                              <div class="info-onmask" @click="checkDetail(item)">查看详情</div>
                              <div class="mask-btn">
                                <el-button
                                  v-if="!item.isDefault"
@@ -233,6 +229,7 @@
                          >
                            <div class="mask">
                              <el-button
                                size="small"
                                type="primary"
                                class="bot-btn"
                                @click="downloadApp(item)"
@@ -419,6 +416,134 @@
                  </div>
                </el-drawer>
              </el-tab-pane>
              <el-tab-pane name="update">
                <span slot="label">
                  <el-badge class="update-badge" :value="updateNum">更新</el-badge>
                </span>
                <div class="task-list">
                  <div class="flex-title">
                    <p class="src-title">算法软件</p>
                    <el-button @click="batchUpdate('sdk')" size="mini" type="primary">更新全部</el-button>
                  </div>
                  <div class="flex-list">
                    <div v-if="!hasNewVersionSdk.length" class="empty-tip">暂无数据,请稍后重试...</div>
                    <div class="wrap-box" v-for="item in hasNewVersionSdk" :key="item.id">
                      <div class="list-choose-item-left">
                        <div class="list-complete-item-handle">
                          <div
                            class="svg-wrap"
                            :class="{willUpGrade:item.isUpgrade}"
                            v-loading="item.upgradeLoading"
                            :element-loading-text="item.progressMsg"
                            element-loading-background="rgba(0,0,0,.8)"
                          >
                            <i class="iconfont iconupdate" v-if="item.isUpgrade"></i>
                            <div class="mask" v-if="!item.isDefault || item.isUpgrade">
                              <div class="left-top">
                                <div>当前版本:{{item.version}}</div>
                                <div v-if="item.remoteVersion">最新版本:{{item.remoteVersion}}</div>
                              </div>
                              <div class="info-onmask" @click="checkDetail(item)">查看详情</div>
                              <div class="mask-btn">
                                <el-button
                                  @click="unLoadSdk(item)"
                                  type="primary"
                                  size="small"
                                  class="bot-btn"
                                >卸载</el-button>
                                <el-button
                                  v-if="item.isUpgrade"
                                  @click="donwload(item)"
                                  type="warning"
                                  size="small"
                                  class="bot-btn"
                                >升级</el-button>
                              </div>
                            </div>
                            <img
                              v-if="item.iconBlob"
                              class="baseImg"
                              :src="item.iconBlob.indexOf(',')>0? item.iconBlob:`data:image/png;base64,${item.iconBlob}`"
                              alt
                            />
                            <img v-else class="baseImg" :src="item.icon" alt />
                          </div>
                          <div class="alg-name">
                            <div style="padding:0px 10px 0px 10px;">
                              <span v-if="!item.isEdit">{{ item.sdk_name}}</span>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="flex-title">
                    <p class="src-title">应用软件</p>
                    <el-button @click="batchUpdate('app')" type="primary" size="mini">更新全部</el-button>
                  </div>
                  <div class="flex-list">
                    <div v-if="!hasNewVersionApp.length" class="empty-tip">暂无数据,请稍后重试...</div>
                    <div class="wrap-box" v-for="item in hasNewVersionApp" :key="item.id">
                      <div class="list-choose-item-left">
                        <div class="list-complete-item-handle">
                          <div
                            class="svg-wrap"
                            :class="{willUpGrade:item.isUpgrade}"
                            v-loading="item.unloadLoading||item.upgradeLoading"
                            :element-loading-text="item.progressMsg"
                            element-loading-background="rgba(0,0,0,.8)"
                          >
                            <i class="iconfont iconupdate" v-if="item.isUpgrade"></i>
                            <div class="mask">
                              <div class="left-top">
                                <div>当前版本:{{item.version}}</div>
                                <div v-if="item.remoteVersion">最新版本:{{item.remoteVersion}}</div>
                              </div>
                              <div class="info-onmask" @click="checkDetail(item)">查看详情</div>
                              <div class="mask-btn">
                                <el-button
                                  v-if="!item.isDefault"
                                  @click="unLoad(item)"
                                  type="primary"
                                  size="small"
                                  class="bot-btn"
                                >卸载</el-button>
                                <el-button
                                  v-if="item.isUpgrade"
                                  @click="downloadApp(item,'upgrade')"
                                  type="warning"
                                  size="small"
                                  class="bot-btn"
                                >升级</el-button>
                              </div>
                            </div>
                            <img
                              v-if="item.iconBlob"
                              class="baseImg"
                              :src="item.iconBlob.indexOf(',')>0? item.iconBlob:`data:image/png;base64,${item.iconBlob}`"
                              alt
                            />
                            <img v-else class="baseImg" :src="item.icon" alt />
                          </div>
                          <div class="alg-name">
                            <div style="padding:0px 10px 0px 10px;">
                              <span v-if="!item.isEdit">{{ item.name }}</span>
                              <el-input
                                size="small"
                                v-model="item.sdk_name"
                                v-if="item.isEdit"
                                v-focus
                                :maxlength="15"
                                @blur="inputBlur(item)"
                              ></el-input>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
@@ -470,11 +595,75 @@
        <el-button type="primary" @click="offlineInstall">安 装</el-button>
      </div>
    </el-dialog>
    <!-- <div class="dialog-content" v-if="productDetailVisible" > -->
    <el-dialog
      class="product-detail-dialog"
      :visible="productDetailVisible"
      @close="productDetailVisible=false"
    >
      <div class="dialog-title" slot="title">算法/应用详情</div>
      <div class="dialog-content">
        <div class="box-top">
          <div class="top-left">
            <div class="banner">
              <!-- <el-carousel
                ref="carousel"
                :autoplay="false"
                indicator-position="none"
                :arrow="curCheckTarget.pics.length > 1 ? 'always' : 'never'"
                @change="changeHandle"
              >
                <el-carousel-item v-for="(item, index) in curCheckTarget.pics" :key="index">
                  <div class="imgwrap">
                    <img
                      v-if="item.type=='image'"
                      :src="'/httpImage/'+item.url"
                      class="cursor-pointer"
                      preview
                    />
                    <video v-if="item.type=='video'" :src="'/httpImage/'+item.url" controls></video>
                  </div>
                </el-carousel-item>
              </el-carousel>-->
            </div>
          </div>
          <div class="top-right">
            <div class="summary">
              <div class="icon"></div>
              <div class="name"></div>
              <!-- <div class="tags">
                <span
                  class="tag"
                  v-for="(id, index) in curCheckTarget.productLabelId"
                  :key="index+'i'"
                >{{showNameById(id)}}</span>
              </div>-->
              <div class="btns">
                <el-button size="mini">升级</el-button>
                <el-button size="mini">卸载</el-button>
                <el-button size="mini">打开</el-button>
              </div>
            </div>
            <div class="product-intruduction">
              <div class="title">产品简介</div>
            </div>
          </div>
        </div>
        <div class="box-bot">
          <div class="bot-left">
            <div class="part-title">功能特点</div>
          </div>
          <div class="bot-right">
            <div class="part-title">推荐算法</div>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { findAllSdk, downloadSdk, installSdk, getInstallInfo } from "./api";
import { findAllSdk, downloadSdk, installSdk, getInstallInfo, removeSdk } from "./api";
import { getApps, installApp, removeApp, getUnActivedSdk, actPageAlg, getUnActivedApp, actApp } from "@/api/app";
import FileUploader from "@/components/subComponents/FileUpload/index";
@@ -485,6 +674,9 @@
    FileUploader
  },
  computed: {
    updateNum () {
      return this.hasNewVersionApp.length + this.hasNewVersionSdk.length
    },
    // notInstalledList () {
    //   return this.sdkList.filter(sdk => {
    //     return sdk.installed === false;
@@ -505,7 +697,7 @@
    //   });
    //   return arr;
    // },
    isAdmin() {
    isAdmin () {
      if (
        sessionStorage.getItem("userInfo") &&
        sessionStorage.getItem("userInfo") !== ""
@@ -517,11 +709,12 @@
      return false;
    },
  },
  data() {
  data () {
    return {
      sdkList: [],
      installedList: [],
      ungradeList: [],
      hasNewVersionSdk: [],
      hasNewVersionApp: [],
      notInstalledList: [],
      buttonAuthority: sessionStorage.getItem("buttonAuthoritys") || [],
      activeName: "myAlgorithm",
@@ -557,8 +750,11 @@
      storeApps: [],
      installFile: {},
      freshTimer: null,
      appUpgreading: false,
      sdkUpgreading: false
      appUpgreading: true,
      sdkUpgreading: true,
      autoRefresh: true,
      curCheckTarget: {},
      productDetailVisible: false,
    }
  },
  directives: {
@@ -568,20 +764,38 @@
      }
    }
  },
  mounted() {
  mounted () {
    // 获取所有应用
    this.getAllSdk();
    this.getAllApps();
    this.autoRefreshAppAndSdkState();
    this.getUnActivedList();
    this.getUnActivedAppList();
  },
  beforeDestroy () {
    this.autoRefresh = false;
  },
  methods: {
    isShow(authority) {
    isShow (authority) {
      return this.isAdmin || this.buttonAuthority.indexOf("," + authority + ",") > -1
    },
    batchUpdate (type) {
      if (type == "sdk") {
        this.hasNewVersionSdk.forEach(sdk => {
          this.donwload(sdk)
        })
      } else {
        this.hasNewVersionApp.forEach(app => {
          this.downloadApp(app, 'upgrade')
        })
      }
    },
    checkDetail (item) {
      this.curCheckTarget = item;
      debugger
      this.productDetailVisible = true;
    },
    //离线安装
    offlineInstall() {
    offlineInstall () {
      this.installDialogVisible = false;
      this.isInstall = true;
      //安装
@@ -590,11 +804,10 @@
          this.isInstall = false;
          this.$message({
            type: 'success',
            message: '安装成功,将跳转至我的算法中查看'
            message: '安装成功,将跳转至"已激活"中查看'
          });
          setTimeout(() => {
            this.getAllSdk();
            this.getAllApps();
            window.parent.postMessage({
              msg: "AppUpdate"
            }, '*')
@@ -611,7 +824,7 @@
        });
      })
    },
    downloadApp(app, action) {
    downloadApp (app, action) {
      if (action == 'upgrade') {
        app.upgradeLoading = true;
      } else {
@@ -624,18 +837,18 @@
          setTimeout(() => {
            if (action == 'upgrade') {
              app.upgradeLoading = false;
              _this.$notify({
                type: 'success',
                message: '升级成功'
              });
              // _this.$notify({
              //   type: 'success',
              //   message: '升级成功'
              // });
            } else {
              app.installLoading = false;
              _this.$notify({
                type: 'success',
                message: '安装成功'
              });
              // _this.$notify({
              //   type: 'success',
              //   message: '安装成功'
              // });
            }
            _this.getAllApps();
            // _this.getAllApps();
            window.parent.postMessage({
              msg: "AppUpdate"
            }, '*')
@@ -652,12 +865,11 @@
      // 开启自动刷新
      this.appUpgreading = true;
      this.startAutoFresh();
    },
    async getAllApps() {
    async getAllApps () {
      let iArry = []
      let sArry = []
      let nArry = []
      let rsp = await getApps();
      if (rsp && rsp.success) {
        // 遍历app的过程重置
@@ -669,36 +881,56 @@
            obj.upgradeLoading = true;
            this.appUpgreading = true;
            this.startAutoFresh();
          }
          item.installed ? iArry.push(obj) : sArry.push(obj)
          item.installed ? iArry.push(obj) : sArry.push(obj);
          item.isUpgrade && nArry.push(obj)
        });
      }
      this.installedApps = iArry;
      this.storeApps = sArry;
      this.hasNewVersionApp = nArry;
    },
    //卸载算法
    unLoadSdk (sdk) {
      let _this = this;
      this.$confirm('确定要卸载该算法吗?', '提示').then(() => {
        sdk.unloadLoading = true;
        removeSdk({ sdkId: sdk.id }).then(res => {
          if (res && res.success) {
            sdk.unloadLoading = false;
            _this.getAllSdk();
            window.parent.postMessage({
              msg: "AppUpdate"
            }, '*')
          }
        }).catch(e => {
          console.log(e);
          sdk.unloadLoading = false;
        })
      }).catch(e => {
        console.log(e)
      })
    },
    //卸载应用
    unLoad(app) {
      app.unloadLoading = true;
    unLoad (app) {
      let _this = this;
      removeApp({ appId: app.id }).then(res => {
        if (res && res.success) {
          //setTimeout(() => {
      this.$confirm('确定要卸载该应用吗?', '提示').then(() => {
        app.unloadLoading = true;
        removeApp({ appId: app.id }).then(res => {
          if (res && res.success) {
            app.unloadLoading = false;
            _this.getAllApps();
            window.parent.postMessage({
              msg: "AppUpdate"
            }, '*')
          }
        }).catch(e => {
          console.log(e);
          app.unloadLoading = false;
          _this.getAllApps();
          window.parent.postMessage({
            msg: "AppUpdate"
          }, '*')
          //}, 3000);
        }
        })
      }).catch(e => {
        console.log(e);
        app.unloadLoading = false;
        console.log(e)
      })
    },
    // actSdk (id) {
    //   this.actSdkId = id;
@@ -707,7 +939,7 @@
    //   this.activeCode = '';
    //   this.activedSdkOrApp = this.newActInfo()
    // },
    actSdkOrApp(id, type = 'sdk') {
    actSdkOrApp (id, type = 'sdk') {
      this.actType = type;
      this.actId = id;
      this.actDrawerShow = true;
@@ -715,7 +947,7 @@
      this.activeCode = '';
      this.activedSdkOrApp = this.newActInfo()
    },
    newActInfo() {
    newActInfo () {
      return {
        activateCode: '',
        productName: '',
@@ -725,7 +957,7 @@
        devIds: ''
      }
    },
    getUnActivedList() {
    getUnActivedList () {
      getUnActivedSdk().then(res => {
        if (res.code == 200) {
          this.unActivedSDKList = res.data;
@@ -733,14 +965,14 @@
      })
    },
    getUnActivedAppList() {
    getUnActivedAppList () {
      getUnActivedApp().then(res => {
        if (res.code == 200) {
          this.unActivedAppList = res.data;
        }
      });
    },
    actived() {
    actived () {
      let _this = this;
      if (this.actType == 'sdk') {
        //激活算法
@@ -778,12 +1010,12 @@
        });
      }
    },
    getCodeDetail() { },
    checkMyAlgorith() {
    getCodeDetail () { },
    checkMyAlgorith () {
      this.actDrawerShow = false;
      this.activeName = "myAlgorithm";
    },
    onFileUpload(file) {
    onFileUpload (file) {
      //this.patchUpdateStatus = `<span style="color:green">上传成功, 点击升级按钮开始安装</span>`;
      this.patchFile = { ...file };
      this.fileAdded = true;
@@ -820,47 +1052,37 @@
    },
    onFileAdded(f) {
    onFileAdded (f) {
      this.patchUpdateStatus = "";
    },
    async getAllSdk() {
    async getAllSdk () {
      let installedList = [];
      let unInstalledList = [];
      let hasNewVersionList = [];
      let res = await findAllSdk();
      if (res && res.success) {
        this.sdkUpgreading = false;
        res.data.forEach(item => {
          let obj = Object.assign({ unloadLoading: false, upgradeLoading: false }, item)
          if (obj.progressMsg !== "" && obj.progressMsg !== "已安装") {
            obj.upgradeLoading = true;
            this.appUpgreading = true;
            this.startAutoFresh();
            this.sdkUpgreading = true;
          }
          //算法软件 已安装其中包含待升级 未安装
          item.installed ? installedList.push(obj) : unInstalledList.push(obj)
        });
        // this.sdkList = res.data.map((i, index) => {
        //   if (i.progressMsg !== "" && i.progressMsg !== "已安装") {
        //     i.upgradeLoading = true;
        //     this.appUpgreading = true;
        //     this.startAutoFresh();
        //   }
        //   this.$set(i, "isEdit", false);
        //   return i;
        // });
      }
      this.installedList = installedList;
      this.notInstalledList = unInstalledList;
      this.hasNewVersionSdk = hasNewVersionList;
    },
    donwload(item) {
    donwload (item) {
      item.upgradeLoading = true;
      //this.downloading = true;
      this.downloadItem = item.id;
@@ -874,7 +1096,6 @@
          item.upgradeLoading = false;
          //this.downloading = false;
          this.downloadItem = "";
          this.getAllSdk();
        })
        .catch(err => {
          this.$notify({
@@ -886,30 +1107,33 @@
          this.downloadItem = "";
        });
      // 开启自动刷新
      this.appUpgreading = true;
      this.startAutoFresh();
      this.sdkUpgreading = true;
    },
    inputBlur(item) {
    inputBlur (item) {
      // console.log(item, '修改名称')
      this.$set(item, "isEdit", false);
    },
    handleTabClick() {
    handleTabClick () {
    },
    startAutoFresh() {
      if (this.freshTimer) {
        clearTimeout(this.freshTimer)
    autoRefreshAppAndSdkState () {
      // 关闭后退出
      if (!this.autoRefresh) {
        return;
      }
      if (!this.appUpgreading && !this.sdkUpgreading) {
        this.freshTimer = -1
        return
      if (this.appUpgreading) {
        this.getAllApps();
      }
      this.getAllSdk()
      this.getAllApps()
      if (this.sdkUpgreading) {
        this.getAllSdk();
      }
      this.freshTimer = setTimeout(this.startAutoFresh, 5 * 1000)
      let _this = this
      setTimeout(() => {
        _this.autoRefreshAppAndSdkState();
      }, 500)
    }
  }
};
@@ -947,6 +1171,22 @@
    width: 100%;
    height: 100%;
  }
  .product-detail-dialog {
    .el-dialog__header {
      text-align: center;
    }
    .dialog-content {
      .box-top {
      }
      .box-bot {
      }
    }
  }
}
.flex-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-loading-mask .el-loading-spinner {
@@ -979,12 +1219,20 @@
.src-title {
  //color: #bfbfbf;
  color: #bbcee8;
  font-family: "PingFangSC-Semibold", "PingFang SC Semibold", "PingFang SC";
  font-family: 'PingFangSC-Semibold', 'PingFang SC Semibold', 'PingFang SC';
  font-weight: 650;
  font-style: normal;
  height: 36px;
  font-size: 15px;
  padding-left: 25px;
}
.update-badge .el-badge__content.is-fixed {
  top: 10px;
  right: 4px;
}
.empty-tip {
  padding-left: 25px;
  color: #ccc;
}
.task-manage {
  height: 100%;
@@ -1004,7 +1252,7 @@
      position: absolute;
      top: 50%;
      left: 50%;
      background: url("/images/algo/green.gif");
      background: url('/images/algo/green.gif');
      overflow: hidden;
      transform: translate(-50%, -50%);
      .inner-bar {
@@ -1075,6 +1323,7 @@
          display: flex;
          flex-direction: row;
          flex-wrap: wrap;
          min-height: 200px;
          .wrap-box {
            width: 16.66%;
          }
@@ -1166,16 +1415,16 @@
        }
      }
      .drawer-content {
        font-family: "PingFangSC-Regular";
        font-family: 'PingFangSC-Regular';
        .el-step__title.is-process {
          border-color: #3d68e1 !important;
          color: #3d68e1 !important;
          font-family: Tahoma, Helvetica, Arial, "\5B8B\4F53", sans-serif;
          font-family: Tahoma, Helvetica, Arial, '\5B8B\4F53', sans-serif;
        }
        .el-step__head.is-process {
          border-color: #3d68e1 !important;
          color: #3d68e1 !important;
          font-family: Tahoma, Helvetica, Arial, "\5B8B\4F53", sans-serif;
          font-family: Tahoma, Helvetica, Arial, '\5B8B\4F53', sans-serif;
        }
        .el-input {
          width: 100%;
@@ -1234,7 +1483,14 @@
      border-radius: 3px;
      display: none;
      .info-onmask {
        color: #8ecaff;
        color: #fff;
      }
      .left-top {
        position: absolute;
        left: 5px;
        top: 5px;
        font-size: 12px;
        color: #90d6ff;
      }
      .mask-btn {
        width: 100%;