From 902018925188ae12fe11cea86435be7dddcadbe8 Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Sat, 18 Jan 2025 17:31:23 +0800
Subject: [PATCH] oss存储配置修改完善,机场增加存储对象配置

---
 vite.config.mjs              |    4 
 src/views/resource/oss.vue   |   55 +++++++++-
 src/api/resource/oss.js      |   23 ++++
 src/api/device/ossBind.js    |   45 +++++++++
 src/views/device/airport.vue |  138 +++++++++++++++++++++++++--
 src/types/oss.js             |   26 +++++
 6 files changed, 271 insertions(+), 20 deletions(-)

diff --git a/src/api/device/ossBind.js b/src/api/device/ossBind.js
new file mode 100644
index 0000000..7eb4ca1
--- /dev/null
+++ b/src/api/device/ossBind.js
@@ -0,0 +1,45 @@
+import request from '@/axios';
+
+export const remove = ids => {
+  return request({
+    url: '/drone-yw/oss/bind/delete',
+    method: 'post',
+    params: {
+      ids,
+    },
+  });
+};
+
+export const deleteByOssId = ossId => {
+  return request({
+    url: '/drone-yw/oss/bind/deleteByOssId',
+    method: 'post',
+    params: {
+      ossId,
+    },
+  });
+};
+
+export const add = row => {
+  return request({
+    url: '/drone-yw/oss/bind/add',
+    method: 'post',
+    data: row,
+  });
+};
+
+export const update = row => {
+  return request({
+    url: '/drone-yw/oss/bind/update',
+    method: 'post',
+    data: row,
+  });
+};
+
+export const addOrUpdate = row => {
+  return request({
+    url: '/drone-yw/oss/bind/addOrUpdate',
+    method: 'post',
+    data: row,
+  });
+};
\ No newline at end of file
diff --git a/src/api/resource/oss.js b/src/api/resource/oss.js
index c126296..d850652 100644
--- a/src/api/resource/oss.js
+++ b/src/api/resource/oss.js
@@ -12,6 +12,18 @@
   });
 };
 
+export const getListPage = (current, size, params) => {
+  return request({
+    url: '/blade-resource/oss/page',
+    method: 'get',
+    params: {
+      ...params,
+      current,
+      size,
+    },
+  });
+};
+
 export const getDetail = id => {
   return request({
     url: '/blade-resource/oss/detail',
@@ -57,3 +69,14 @@
     },
   });
 };
+
+export const disable = id => {
+  return request({
+    url: '/blade-resource/oss/disable',
+    method: 'post',
+    params: {
+      id,
+    },
+  });
+};
+
diff --git a/src/types/oss.js b/src/types/oss.js
new file mode 100644
index 0000000..3933c73
--- /dev/null
+++ b/src/types/oss.js
@@ -0,0 +1,26 @@
+// oss 类型
+export let OSS_TYPE;
+(function (OSS_TYPE) {
+  OSS_TYPE[(OSS_TYPE['minio'] = 1)] = 'minio';
+  OSS_TYPE[(OSS_TYPE['七牛云'] = 2)] = '七牛云';
+  OSS_TYPE[(OSS_TYPE['阿里云'] = 3)] = '阿里云';
+  OSS_TYPE[(OSS_TYPE['腾讯云'] = 4)] = '腾讯云';
+  OSS_TYPE[(OSS_TYPE['华为云'] = 5)] = '华为云';
+  OSS_TYPE[(OSS_TYPE['amazon s3'] = 6)] = 'amazon s3';
+})(OSS_TYPE || (OSS_TYPE = {}));
+
+
+export let OssTypeText = {
+  minio: 1,
+  七牛云: 2,
+  阿里云: 3,
+  腾讯云: 4,
+  华为云: 5,
+  amazons3: 6,
+  1: 'minio',
+  2: '七牛云',
+  3: '阿里云',
+  4: '腾讯云',
+  5: '华为云',
+  6: 'amazons3',
+};
\ No newline at end of file
diff --git a/src/views/device/airport.vue b/src/views/device/airport.vue
index 9b79dbd..d5d189c 100644
--- a/src/views/device/airport.vue
+++ b/src/views/device/airport.vue
@@ -110,10 +110,10 @@
         <el-button
           type="primary"
           text
-          icon="el-icon-collection-tag"
-          v-if="permission.deviceFirmware_manage"
-          @click.stop="handleOpenFirmwarm(scope.row, scope.index)"
-          >固件管理
+          icon="el-icon-paperclip"
+          v-if="permission.oss_set"
+          @click.stop="handleOpenOssSet(scope.row, scope.index)"
+          >存储配置
         </el-button>
         <el-button
           type="primary"
@@ -142,6 +142,41 @@
         <span class="dialog-footer">
           <el-button @click="firmwareBox = false">取 消</el-button>
           <el-button type="primary" @click="updateFirmwareConfirm">确 定</el-button>
+        </span>
+      </template>
+    </el-dialog>
+
+    <el-dialog
+      title="存储配置"
+      append-to-body
+      v-model="ossSetBox"
+      @close="handleOssSetClose"
+      width="600px"
+    >
+      <div style="display: flex; flex-direction: row; align-items: center">
+        存储对象配置:
+        <el-select v-model="ossEnd" clearable placeholder="请选择存储对象" style="width: 450px">
+          <el-option
+            v-for="item in ossList"
+            :key="item.id"
+            :label="item.name + ': ' + item.endpoint"
+            :value="item.id"
+          >
+            <span style="float: left">{{ item.name + ': ' + item.endpoint }}</span>
+            <span v-if="item.status == 1" style="float: right; color: #8492a6; font-size: 13px">{{
+              item.categoryName
+            }}</span>
+            <span v-if="item.status == 2" style="float: right; color: #40cb8b; font-size: 13px">{{
+              item.categoryName
+            }}</span>
+          </el-option>
+        </el-select>
+      </div>
+      <template #footer>
+        <span class="dialog-footer">
+          <el-button @click="cancelOssSet">取 消</el-button>
+          <el-button type="danger" @click="cancelOssSetConfirm">取消配置</el-button>
+          <el-button type="primary" @click="ossSetConfirm">配置</el-button>
         </span>
       </template>
     </el-dialog>
@@ -204,7 +239,8 @@
   getDeviceFirmwareList,
   getDevices,
 } from '@/api/device/device';
-
+import { deleteByOssId, addOrUpdate as addOrUpdateOssBind } from '@/api/device/ossBind';
+import { getListPage as getOssList } from '@/api/resource/oss';
 import { getLazyTree } from '@/api/base/region';
 import { EDockModeText, EDockModeCode } from '@/types/device';
 import { mapGetters } from 'vuex';
@@ -219,10 +255,14 @@
     DevicePerShare,
     DockControlPanel,
   },
-
   data() {
     return {
-      operateTitle:"",
+      bindOssId: null,
+      deviceSn: '',
+      ossSetBox: false,
+      ossList: [],
+      ossEnd: '',
+      operateTitle: '',
       rollFirmVersion: '',
       firmList: [],
       rollFirmwareBox: false,
@@ -607,12 +647,12 @@
       });
     },
     init() {
-      this.page= {
+      (this.page = {
         pageSize: 10,
         currentPage: 1,
         total: 0,
-      },
-      this.onLoad(this.page);
+      }),
+        this.onLoad(this.page);
     },
     // 打开权限分享页面
     handleOpenDevicePerShare(row) {
@@ -626,9 +666,24 @@
     handleOpenRemoteDebugging(row) {
       this.curDeviceInfo = row;
       this.remoteDebuggingShow = true;
-      this.operateTitle = row.nickname + " - " + row.device_sn
+      this.operateTitle = row.nickname + ' - ' + row.device_sn;
     },
-
+    // 打开存储对象配置页面
+    handleOpenOssSet(row) {
+      var that = this;
+      this.deviceSn = row.device_sn;
+      this.ossSetBox = true;
+      this.bindOssId = row.oss_id;
+      this.ossEnd = row.oss_id;
+      // 查询下拉列表
+      const param = {
+        categoryKeys: "1,3,6"
+      }
+      getOssList(1, 50,param).then(res => {
+        const data = res.data.data;
+        that.ossList = data.records;
+      });
+    },
     // 打开固件管理页面
     handleOpenFirmwarm(row) {
       var that = this;
@@ -824,6 +879,65 @@
         done();
       });
     },
+    handleOssSetClose() {
+      this.ossEnd = '';
+      this.deviceSn = '';
+      this.bindOssId = null;
+    },
+    // 存储对象配置确定
+    ossSetConfirm() {
+      var that = this;
+      // 判断是否已选择
+      if (!this.ossEnd) {
+        this.$message({
+          type: 'warning',
+          message: '请选择对于的存储对象!',
+        });
+        return;
+      }
+      // 新增或者修改操作
+      const data = {
+        oss_id: this.ossEnd,
+        sn: this.deviceSn,
+      };
+      // 新增
+      addOrUpdateOssBind(data).then(res => {
+        this.$message({
+          type: 'success',
+          message: '操作成功!',
+        });
+        that.ossSetBox = false;
+        this.onLoad(this.page);
+        done();
+      });
+    },
+    // 取消配置
+    cancelOssSetConfirm() {
+      var that = this;
+      // 判断是否已有配置
+      if (!this.bindOssId) {
+        this.$message({
+          type: 'warning',
+          message: '当前机场尚未配置存储对象信息!',
+        });
+        return;
+      }
+      deleteByOssId(this.bindOssId).then(() => {
+        that.ossSetBox = false;
+        this.onLoad(this.page);
+        this.$message({
+          type: 'success',
+          message: '操作成功!',
+        });
+      });
+    },
+    // 取消按钮 oss
+    cancelOssSet() {
+      this.ossEnd = '';
+      this.deviceSn = '';
+      this.bindOssId = null;
+      this.ossSetBox = false;
+    },
     rowSave(row, done, loading) {
       add(row).then(
         () => {
diff --git a/src/views/resource/oss.vue b/src/views/resource/oss.vue
index c7de273..9c0eef2 100644
--- a/src/views/resource/oss.vue
+++ b/src/views/resource/oss.vue
@@ -43,9 +43,17 @@
           type="primary"
           text
           icon="el-icon-circle-check"
-          v-if="permission.oss_enable"
+          v-if="scope.row.status==1 && permission.oss_enable"
           @click.stop="handleEnable(scope.row)"
           >启用
+        </el-button>
+        <el-button
+          type="primary"
+          text
+          icon="VideoPause"
+          v-if="scope.row.status==2 && permission.oss_enable"
+          @click.stop="handleDisable(scope.row)"
+          >禁用
         </el-button>
       </template>
       <template #status="{ row }">
@@ -62,7 +70,7 @@
 </template>
 
 <script>
-import { getList, getDetail, add, update, remove, enable } from '@/api/resource/oss';
+import { getListPage, getDetail, add, update, remove, enable, disable } from '@/api/resource/oss';
 import { mapGetters } from 'vuex';
 import func from '@/utils/func';
 
@@ -89,7 +97,7 @@
         index: true,
         viewBtn: true,
         selection: true,
-        grid: true,
+        grid: false,
         menuWidth: 350,
         labelWidth: 100,
         dialogWidth: 880,
@@ -102,6 +110,7 @@
             span: 24,
             width: 120,
             searchLabelWidth: 50,
+            searchSpan:3,
             row: true,
             dicUrl: '/blade-system/dict/dictionary?code=oss',
             props: {
@@ -121,11 +130,27 @@
             ],
           },
           {
+            label: '名称',
+            prop: 'name',
+            span: 24,
+            search: true,
+            searchSpan:5,
+            rules: [
+              {
+                required: true,
+                message: '请输入名称',
+                trigger: 'blur',
+              },
+            ],
+          },
+          {
             label: '资源编号',
             prop: 'ossCode',
             span: 24,
             width: 120,
+            searchLabelWidth: 100,
             search: true,
+            searchSpan:4,
             rules: [
               {
                 required: true,
@@ -171,7 +196,8 @@
             prop: 'accessKey',
             span: 24,
             search: true,
-            width: 200,
+            searchSpan:5,
+            searchLabelWidth: 100,
             overHidden: true,
             rules: [
               {
@@ -185,7 +211,6 @@
             label: 'secretKey',
             prop: 'secretKey',
             span: 24,
-            width: 200,
             overHidden: true,
             rules: [
               {
@@ -378,6 +403,24 @@
           this.$refs.crud.toggleSelection();
         });
     },
+    handleDisable(row){
+      this.$confirm('是否确定禁用用这条配置?', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning',
+      })
+        .then(() => {
+          return disable(row.id);
+        })
+        .then(() => {
+          this.onLoad(this.page);
+          this.$message({
+            type: 'success',
+            message: '操作成功!',
+          });
+          this.$refs.crud.toggleSelection();
+        });
+    },
     handleDebug(row) {
       this.box = true;
       this.debugForm.code = row.ossCode;
@@ -431,7 +474,7 @@
     },
     onLoad(page, params = {}) {
       this.loading = true;
-      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
+      getListPage(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
         const data = res.data.data;
         this.page.total = data.total;
         this.data = data.records;
diff --git a/vite.config.mjs b/vite.config.mjs
index b610064..df3da37 100644
--- a/vite.config.mjs
+++ b/vite.config.mjs
@@ -38,8 +38,8 @@
       port: 2888,
       proxy: {
         '/api': {
-          // target: 'http://localhost',
-          target: 'https://wrj.shuixiongit.com/api',
+          target: 'http://localhost',
+          // target: 'https://wrj.shuixiongit.com/api',
           changeOrigin: true,
           rewrite: path => path.replace(/^\/api/, ''),
         },

--
Gitblit v1.9.3