@ddwl/ddwl-ui 1.3.18 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddwl/ddwl-ui",
3
- "version": "1.3.18",
3
+ "version": "1.4.1",
4
4
  "private": false,
5
5
  "main": "dist/index.common.js",
6
6
  "style": "dist/index.css",
@@ -1,4 +1,5 @@
1
1
  import previewVue from '../../packages/file-preview/index.vue'
2
+ import importVue from '../../packages/import-file/index.vue'
2
3
 
3
4
  export default (Vue) => {
4
5
  // 文件预览
@@ -10,4 +11,51 @@ export default (Vue) => {
10
11
  instance.defaultIndex = defaultIndex
11
12
  instance.list = list
12
13
  }
14
+
15
+ // 文件导入
16
+ Vue.prototype.$importFile = ({
17
+ width = '520px',
18
+ title = '文件导入',
19
+ templateUrl = '',
20
+ token = '',
21
+ templateDownloadMethod = null,
22
+ fileType = ['xlsx', 'xls'],
23
+ fileSize = 5,
24
+ slotRender = null
25
+ }) => {
26
+ return new Promise((resolve, reject) => {
27
+ const Import = Vue.extend(importVue)
28
+ const instance = new Import()
29
+ const el = instance.$mount().$el
30
+ document.body.appendChild(el)
31
+
32
+ instance.value = true
33
+ instance.width = width
34
+ instance.title = title
35
+ instance.templateUrl = templateUrl
36
+ instance.token = token
37
+ instance.templateDownloadMethod = templateDownloadMethod
38
+ instance.fileType = fileType
39
+ instance.fileSize = fileSize
40
+ instance.slotRender = slotRender
41
+
42
+ const destroy = () => {
43
+ instance.$destroy()
44
+ el.parentNode && el.parentNode.removeChild(el)
45
+ }
46
+
47
+ instance.$on('submit', async (callback, file) => {
48
+ try {
49
+ resolve({ file, callback })
50
+ } catch (e) {
51
+ callback(new Error(e))
52
+ }
53
+ })
54
+
55
+ instance.$on('close', () => {
56
+ reject()
57
+ Vue.nextTick(destroy)
58
+ })
59
+ })
60
+ }
13
61
  }
package/src/main.js CHANGED
@@ -6,7 +6,6 @@ import Drawer from './packages/drawer'
6
6
  import FilterTree from './packages/filter-tree'
7
7
  import Form from './packages/form'
8
8
  import FormItem from './packages/form-item'
9
- import ImportFile from './packages/import-file'
10
9
  import Menu from './packages/menu'
11
10
  import Popconfirm from './packages/popconfirm'
12
11
  import Render from './packages/render'
@@ -31,7 +30,6 @@ const components = [
31
30
  FilterTree,
32
31
  Form,
33
32
  FormItem,
34
- ImportFile,
35
33
  Menu,
36
34
  Popconfirm,
37
35
  Render,
@@ -39,27 +39,27 @@
39
39
  模板下载
40
40
  </el-button>
41
41
  </el-form>
42
- <slot>
42
+ <div v-if="slotRender">
43
+ <d-render :render="slotRender" />
44
+ </div>
45
+ <div v-else>
43
46
  <p>1. 支持导入格式为{{ fileType.join('、') }}的文件,且文件大小不可超过{{ fileSize }}M</p>
44
47
  <p>2. 模板的表头不可更改,不可删除</p>
45
48
  <p>3. 若导入数据存在编码一致的情况则会更新原有数据</p>
46
49
  <p>4. 若导入过程中有问题,需调整模板内容后再重新导入</p>
47
- </slot>
50
+ </div>
48
51
  </d-dialog>
49
52
  </template>
50
53
 
51
54
  <script>
52
55
  import DDialog from '../dialog'
56
+ import DRender from '../render'
53
57
 
54
58
  export default {
55
59
  name: 'DImportFile',
56
- components: { DDialog },
57
- model: {
58
- prop: 'modelValue',
59
- event: 'change'
60
- },
60
+ components: { DDialog, DRender },
61
61
  props: {
62
- modelValue: {
62
+ value: {
63
63
  default: false,
64
64
  type: Boolean
65
65
  },
@@ -75,6 +75,10 @@ export default {
75
75
  default: '',
76
76
  type: String
77
77
  },
78
+ token: {
79
+ default: '',
80
+ type: String
81
+ },
78
82
  templateDownloadMethod: {
79
83
  type: Function,
80
84
  default: null
@@ -86,26 +90,32 @@ export default {
86
90
  fileSize: {
87
91
  default: 5,
88
92
  type: Number
93
+ },
94
+ slotRender: {
95
+ default: null,
96
+ type: Function
89
97
  }
90
98
  },
91
99
  data() {
92
100
  return {
101
+ visible: false,
93
102
  fileList: [],
94
103
  form: {
95
104
  file: ''
96
105
  }
97
106
  }
98
107
  },
99
- computed: {
108
+ watch: {
109
+ value: {
110
+ handler(value) {
111
+ this.visible = value
112
+ }
113
+ },
100
114
  visible: {
101
- get() {
102
- return this.modelValue
103
- },
104
- set(value) {
105
- this.form.file = ''
106
- this.fileList = []
107
- this.$refs.importForm.clearValidate()
108
- this.$emit('change', value)
115
+ handler(value) {
116
+ if (!value) {
117
+ this.$emit('close', value)
118
+ }
109
119
  }
110
120
  }
111
121
  },
@@ -114,13 +124,7 @@ export default {
114
124
  if (this.templateDownloadMethod) {
115
125
  this.templateDownloadMethod()
116
126
  } else {
117
- let token
118
- try {
119
- token = JSON.parse(window.localStorage.getItem('userInfo')).token
120
- } catch (e) {
121
- token = ''
122
- }
123
- window.location.href = `${this.templateUrl}?authToken=${token}`
127
+ window.location.href = `${this.templateUrl}?authToken=${this.token}`
124
128
  }
125
129
  },
126
130
  uploadChange(file, fileList) {
@@ -146,7 +150,7 @@ export default {
146
150
  return
147
151
  }
148
152
  try {
149
- this.$emit('submit', this.form.file, callback)
153
+ this.$emit('submit', callback, this.form.file)
150
154
  } catch (e) {
151
155
  callback(new Error(false))
152
156
  }
@@ -297,6 +297,11 @@ export default {
297
297
  .img-part {
298
298
  width: 80px;
299
299
  height: 80px;
300
+ .el-upload--picture-card {
301
+ width: 80px;
302
+ height: 80px;
303
+ line-height: 80px;
304
+ }
300
305
  }
301
306
  }
302
307
  .file-list {