natasha hai 5 días
pai
achega
2c491e91e2

+ 8 - 0
src/api/book.js

@@ -138,4 +138,12 @@ export function MangerAddResource(data) {
  */
 export function MangerDeleteResource(data) {
   return http.post(`${process.env.VUE_APP_EepServer}?MethodName=project_resource_manager-DeleteResource`, data);
+}
+
+/**
+ * @description 更新项目资源文件
+ * @param {object} data
+ */
+export function MangerUpdateResourceFile(data) {
+  return http.post(`${process.env.VUE_APP_EepServer}?MethodName=project_resource_manager-UpdateResourceFile`, data);
 }

+ 76 - 26
src/views/personal_workbench/project/ProductionResourceManage.vue

@@ -48,10 +48,14 @@
           </div>
         </div>
         <div class="sources-box" :style="{ height: height + 'px' }" v-if="height > 0" v-loading="boxLoading">
-          <div v-for="(item, index) in list" :key="index" @click="selectSourceNode(item)" class="sources-item">
-            <template v-if="type_index === 0">
-              <el-image :src="item.file_url" :preview-src-list="[item.file_url]" fit="contain"></el-image
-            ></template>
+          <div
+            v-for="(item, index) in list"
+            :key="index"
+            @click="selectSourceNode(item)"
+            class="sources-item"
+            :class="[select_sources_id === item.id ? 'active' : '']"
+          >
+            <template v-if="type_index === 0"> <el-image :src="item.file_url" fit="contain"></el-image></template>
             <template v-if="type_index === 1">
               <AudioLine
                 ref="audioLine"
@@ -107,7 +111,12 @@
 <script>
 import MenuPage from '../common/menu.vue';
 import MenuTree from './components/MenuTree.vue';
-import { ChapterGetBookChapterStruct, MangerAddResource, MangerDeleteResource } from '@/api/book';
+import {
+  ChapterGetBookChapterStruct,
+  MangerAddResource,
+  MangerDeleteResource,
+  MangerUpdateResourceFile,
+} from '@/api/book';
 import { GetProjectBaseInfo } from '@/api/project';
 import PaginationPage from '@/components/PaginationPage.vue';
 import { PageQueryProjectResourceList } from '@/api/list';
@@ -283,12 +292,21 @@ export default {
       }
     },
     // 设置信息
-    handleSetInfo() {},
+    handleSetInfo() {
+      if (this.select_sources_id) {
+      } else {
+        this.$message.warning('请先选择文件');
+      }
+    },
     // 更换文件
     handleChangeFile() {
-      this.limit = 1;
-      this.uploadTip = '只能上传 1 个文件';
-      this.sourceAddFlag = true;
+      if (this.select_sources_id) {
+        this.limit = 1;
+        this.uploadTip = '只能上传 1 个文件';
+        this.sourceAddFlag = true;
+      } else {
+        this.$message.warning('请先选择文件');
+      }
     },
 
     // 设置项目成员资源使用权限
@@ -354,23 +372,43 @@ export default {
     // 确定新增资源
     submitAdd() {
       this.loading = true;
-      let data = {
-        project_id: this.book_id,
-        book_chapter_node_id: this.select_node,
-        type: this.type_list[this.type_index].value,
-        file_id_list: this.file_id_list,
-      };
-      MangerAddResource(data)
-        .then((res) => {
-          this.loading = false;
-          this.sourceAddFlag = false;
-          if (res.status === 1) {
-            this.queryList('');
-          }
-        })
-        .catch(() => {
-          this.loading = false;
-        });
+      if (this.limit === 1) {
+        // 更换文件
+        let data = {
+          id: this.select_sources_id,
+          file_id: this.file_id_list[0],
+        };
+        MangerUpdateResourceFile(data)
+          .then((res) => {
+            this.loading = false;
+            this.sourceAddFlag = false;
+            if (res.status === 1) {
+              this.queryList('');
+            }
+          })
+          .catch(() => {
+            this.loading = false;
+          });
+      } else {
+        // 上传文件
+        let data = {
+          project_id: this.book_id,
+          book_chapter_node_id: this.select_node,
+          type: this.type_list[this.type_index].value,
+          file_id_list: this.file_id_list,
+        };
+        MangerAddResource(data)
+          .then((res) => {
+            this.loading = false;
+            this.sourceAddFlag = false;
+            if (res.status === 1) {
+              this.queryList('');
+            }
+          })
+          .catch(() => {
+            this.loading = false;
+          });
+      }
     },
     // 点击资源
     selectSourceNode(item) {
@@ -477,6 +515,7 @@ export default {
 
       .sources-item {
         width: 200px;
+        cursor: pointer;
 
         .el-image {
           width: 100%;
@@ -494,6 +533,17 @@ export default {
         :deep .audioLine {
           background: #f2f3f5;
         }
+
+        &.active {
+          .el-image {
+            border-color: #f90;
+          }
+
+          .name,
+          .label {
+            color: #f90;
+          }
+        }
       }
     }
   }