From 9c094a1fe3e1ae3dadef6433f8401818fe2b8304 Mon Sep 17 00:00:00 2001
From: lzhe <lzhe@example.com>
Date: 星期五, 21 六月 2024 10:53:43 +0800
Subject: [PATCH] 1

---
 src/views/dnc/document/index.vue |  143 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 131 insertions(+), 12 deletions(-)

diff --git a/src/views/dnc/document/index.vue b/src/views/dnc/document/index.vue
index 6e9d974..a88a9d7 100644
--- a/src/views/dnc/document/index.vue
+++ b/src/views/dnc/document/index.vue
@@ -1,7 +1,7 @@
 <!--
  * @Date: 2024-05-16 22:40:01
  * @LastEditors: Sneed
- * @LastEditTime: 2024-05-19 21:25:53
+ * @LastEditTime: 2024-06-18 21:51:57
  * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/dnc/document/index.vue
 -->
 <template>
@@ -11,9 +11,10 @@
                 <el-aside width="200px">
                     <el-container>
                         <el-main>
-                            <el-tree default-expand-all ref="tree" node-key="id" :data="treeData" :props="{
-                                label: 'name',
-                            }" @node-click="nodeClick" highlight-current :current-node-key="selectNode.id">
+                            <el-tree :expand-on-click-node="false" default-expand-all ref="tree" node-key="id"
+                                :data="treeData" :props="{
+                                    label: 'name',
+                                }" @node-click="nodeClick" highlight-current :current-node-key="selectNode.id">
                                 <template #default="{ node, data }">
                                     <span :class="data.isGroup ? 'active' : ''" class="custom-tree-node">
                                         <span>{{
@@ -37,12 +38,16 @@
                             <template #dropdown>
                                 <el-dropdown-menu>
                                     <el-dropdown-item @click="addFolder">鏂囦欢澶�</el-dropdown-item>
-                                    <el-dropdown-item>鏂囦欢</el-dropdown-item>
+                                    <el-dropdown-item @click="addFile">鏂囦欢</el-dropdown-item>
                                 </el-dropdown-menu>
                             </template>
                         </el-dropdown>
-                        <el-upload style="margin-left: 8px;" :show-file-list="false" class="upload"
+                        <!-- <el-upload style="margin-left: 8px;" :show-file-list="false" class="upload"
                             action="/api/blade-resource/oss/endpoint/put-file">
+                            <el-button type="primary">涓婁紶鏂囦欢</el-button>
+                        </el-upload> -->
+                        <el-upload style="margin-left: 8px;" :show-file-list="false" class="upload"
+                            :http-request="request">
                             <el-button type="primary">涓婁紶鏂囦欢</el-button>
                         </el-upload>
                         <!-- <el-button type="primary" style="margin-left: 8px;">涓婁紶鏂囦欢</el-button> -->
@@ -106,9 +111,14 @@
                                 <template #default="scope">
                                     <el-button-group>
                                         <el-button text type="primary" size="small"
-                                            @click="table_edit(scope.row, scope.$index)">缂栬緫</el-button>
-                                        <el-button text type="primary" size="small"
-                                            @click="del([scope.row])">鍒犻櫎</el-button>
+                                            @click="table_edit(scope.row, scope.$index)">閲嶅懡鍚�</el-button>
+                                        <el-popconfirm width="220" title="纭畾灏嗛�夋嫨鐨勬暟鎹垹闄�" @confirm="del([scope.row], '0')">
+                                            <template #reference>
+                                                <el-button text type="primary" size="small">鍒犻櫎</el-button>
+                                            </template>
+                                        </el-popconfirm>
+                                        <!-- <el-button text type="primary" size="small"
+                                            @click="del([scope.row])">鍒犻櫎</el-button> -->
                                     </el-button-group>
                                 </template>
                             </el-table-column>
@@ -117,7 +127,7 @@
                 </el-container>
             </el-container>
         </el-card>
-        <el-dialog v-model="visible" title="鏂板缓鏂囦欢澶�" width="500">
+        <el-dialog v-model="visible" :title="form.id ? '閲嶅懡鍚�' : '鏂板缓鏂囦欢澶�'" width="500">
             <el-form :model="form" :rules="rules" ref="dialogForm" label-width="120px" label-position="center">
                 <el-form-item v-if="form.fileType == 1 || !form.id" label="鏂囦欢澶瑰悕绉�" prop="name">
                     <el-input v-model="form.name" />
@@ -150,6 +160,10 @@
                 </div>
             </template>
         </el-dialog>
+        <scDialog v-model="visible1">
+            <scForm ref="form" :config="config" :rules="rules1" v-model="form1" @submit="submit1">
+            </scForm>
+        </scDialog>
     </el-main>
 </template>
 
@@ -157,9 +171,44 @@
 export default {
     data() {
         return {
+            visible: false,
+            rules1: {
+                name: [{
+                    required: true, message: '蹇呭~'
+                }],
+                content: [{
+                    required: true, message: '蹇呭~'
+                }]
+            },
+            form1: {},
+            config: {
+                labelWidth: 120,
+                formItems: [
+                    {
+                        component: 'input',
+                        label: '鏂囦欢鍚嶇О',
+                        name: 'name',
+                        options: {
+                            placeholder: '',
+                            maxlength: 100,
+                        }
+                    },
+                    {
+                        component: 'input',
+                        label: '鏂囦欢鍐呭',
+                        type: 'textarea',
+                        name: 'content',
+                        options: {
+                            multiple: false,
+                            data: []
+                        },
+                        disabled: false
+                    }
+                ]
+            },
             treeData: [],
             selectNode: {},
-            visible: false,
+            visible1: false,
             form: {},
             rules: {
                 name: [{
@@ -201,6 +250,76 @@
         this.init()
     },
     methods: {
+        request(options) {
+            const formData = new FormData()
+            formData.append('file', options.file)
+            console.log(options)
+            this.$HTTP.post(`/api/blade-resource/oss/endpoint/put-file`, formData).then(resFile => {
+                if (resFile.success) {
+                    this.$HTTP.post(`/api/blade-dnc/file/batch-save`, [{
+                        name: options.file.name,
+                        targetId: this.selectNode.id,
+                        ossFile: {
+                            attachId: resFile.data.attachId,
+                            domain: resFile.data.domain,
+                            link: resFile.data.link,
+                            name: resFile.data.name,
+                            originalName: resFile.data.originalName
+                        }
+                    }]).then(res => {
+                        if (res.success) {
+                            this.visible = false
+                            this.search()
+                        } else {
+                            this.$message.error(res.msg)
+                        }
+                    })
+                } else {
+                    this.$message.error(res.msg)
+                }
+
+            })
+        },
+        addFile() {
+            this.form1 = {}
+            this.$refs?.form?.resetFields()
+            this.visible1 = true
+        },
+        submit1() {
+            // 鍒涘缓鏂囨湰鍐呭
+            const textContent = "杩欓噷鏄枃鏈唴瀹�";
+
+            // 鍒涘缓Blob瀵硅薄
+            const blob = new Blob([this.form1.content], { type: 'text/plain' });
+            // 鍒涘缓File瀵硅薄
+            const file = new File([blob], this.form1.name, { type: 'text/plain', lastModified: new Date().getTime() });
+            const data = new FormData()
+            data.append("file", file);
+            this.$HTTP.post(`/api/blade-resource/oss/endpoint/put-file`, data).then(res => {
+                if (res.success) {
+                    this.$HTTP.post(`/api/blade-dnc/file/batch-save`, [{
+                        name: `${this.form1.name}.txt`,
+                        targetId: this.selectNode.id,
+                        ossFile: {
+                            attachId: res.data.attachId,
+                            domain: res.data.domain,
+                            link: res.data.link,
+                            name: res.data.name,
+                            originalName: res.data.originalName
+                        }
+                    }]).then(res => {
+                        if (res.success) {
+                            this.visible = false
+                            this.search()
+                        } else {
+                            this.$message.error(res.msg)
+                        }
+                    })
+                } else {
+                    this.$message.error(res.msg)
+                }
+            })
+        },
         init() {
             this.selectNode = {
                 id: ''
@@ -235,7 +354,7 @@
             this.selectNode = { id: this.$refs.tree.getCurrentNode().parentId }
         },
         search() {
-            this.$refs?.table.reload()
+            this.$refs?.table?.reload()
         },
         // 鏂板鏂囦欢澶�
         addFolder() {

--
Gitblit v1.9.3