Переглянути джерело

feat(dataset): support for copying

Casper Dai 2 роки тому
батько
коміт
e98a8dfd51

+ 8 - 0
src/api/asset.js

@@ -224,6 +224,14 @@ export function addDataset (data) {
   }, tenantRequest)
 }
 
+export function copyDataset (data) {
+  return messageSend({
+    url: '/media/dataset/copy',
+    method: 'POST',
+    data
+  }, '复制')
+}
+
 export function updateDataset (data) {
   return update({
     url: '/media/dataset',

+ 41 - 2
src/views/ad/automation/dataset/index.vue

@@ -79,7 +79,8 @@ import {
   getDevicesByDataset,
   bindDatasetToDevice,
   unbindDatasetByDevices,
-  unbindDatasetByDevice
+  unbindDatasetByDevice,
+  copyDataset
 } from '@/api/asset'
 import { assetTableMixin } from '../mixins/asset-table'
 
@@ -111,8 +112,9 @@ export default {
           { type: 'invoke', render: [
             { label: '上播内容', on: this.onEdit },
             { label: '关联设备', on: this.onViewDevices },
+            { label: '复制', on: this.onCopy },
             { label: '删除', on: this.onDel }
-          ], width: 200 }
+          ], width: 240 }
         ]
       },
       assetSchema: {
@@ -369,6 +371,43 @@ export default {
         done()
         this.$refs.deviceDialog.getTable().pageTo(1)
       })
+    },
+    onCopy ({ id, name }) {
+      this.$prompt(
+        '<p class="u-color--black u-font-size--sm u-bold">素材包名称</p>',
+        '复制素材包',
+        {
+          dangerouslyUseHTMLString: true,
+          closeOnClickModal: false,
+          inputValue: name.length <= 28 ? `${name}副本` : name,
+          inputPlaceholder: '最多30个字符',
+          inputPattern: /^.{0,30}$/,
+          inputValidator: val => {
+            const inputName = val ? val.replace(/^\s+|\s+$/g, '') : val
+            return inputName
+              ? inputName === name
+                ? '名称不能与源素材包一样'
+                : true
+              : '请填写名称'
+          },
+          inputErrorMessage: '最多30个字符',
+          confirmButtonText: '复制',
+          cancelButtonText: '取消',
+          beforeClose: (action, instance, done) => {
+            if (action === 'confirm') {
+              this.onConfirmCopy(id, instance.inputValue.replace(/^\s+|\s+$/g, ''), done)
+            } else {
+              done()
+            }
+          }
+        }
+      )
+    },
+    onConfirmCopy (id, name, done) {
+      copyDataset({ id, name }).then(() => {
+        done()
+        this.$refs.table.pageTo(1)
+      })
     }
   }
 }

+ 41 - 2
src/views/screen/material/dataset/index.vue

@@ -28,7 +28,8 @@ import {
   updateDataset,
   getCommonDataset,
   deleteDataset,
-  updateDatasetAssets
+  updateDatasetAssets,
+  copyDataset
 } from '@/api/asset'
 
 export default {
@@ -57,8 +58,9 @@ export default {
           { prop: 'updateTime', label: '更新时间', width: 200 },
           { type: 'invoke', render: [
             { label: '上播内容', on: this.onEdit },
+            { label: '复制', on: this.onCopy },
             { label: '删除', on: this.onDel }
-          ] }
+          ], width: 180 }
         ]
       },
       assets: []
@@ -155,6 +157,43 @@ export default {
     },
     onViewAsset ({ file }) {
       this.$refs.previewDialog.show(file)
+    },
+    onCopy ({ id, name }) {
+      this.$prompt(
+        '<p class="u-color--black u-font-size--sm u-bold">素材包名称</p>',
+        '复制素材包',
+        {
+          dangerouslyUseHTMLString: true,
+          closeOnClickModal: false,
+          inputValue: name.length <= 28 ? `${name}副本` : name,
+          inputPlaceholder: '最多30个字符',
+          inputPattern: /^.{0,30}$/,
+          inputValidator: val => {
+            const inputName = val ? val.replace(/^\s+|\s+$/g, '') : val
+            return inputName
+              ? inputName === name
+                ? '名称不能与源素材包一样'
+                : true
+              : '请填写名称'
+          },
+          inputErrorMessage: '最多30个字符',
+          confirmButtonText: '复制',
+          cancelButtonText: '取消',
+          beforeClose: (action, instance, done) => {
+            if (action === 'confirm') {
+              this.onConfirmCopy(id, instance.inputValue.replace(/^\s+|\s+$/g, ''), done)
+            } else {
+              done()
+            }
+          }
+        }
+      )
+    },
+    onConfirmCopy (id, name, done) {
+      copyDataset({ id, name }).then(() => {
+        done()
+        this.$refs.table.pageTo(1)
+      })
     }
   }
 }