xianniu-ui 0.1.4 → 0.1.6

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.
@@ -1,28 +1,57 @@
1
1
  <template>
2
2
  <div class="xn-table-box">
3
3
  <div class="xn-table-box-tools" :class="{ 'is-border': !border }">
4
- <slot name="tools">
5
- <el-button-group>
4
+ <div class="flex justify-content-between align-items-center">
5
+ <div class="fz-12" :class="{'pb-10':selection}">
6
+ <template v-if="selection">
7
+ <span>已选择 {{ selectedData.length }} 项</span>
8
+ <el-button
9
+ type="text"
10
+ v-show="selectedData.length"
11
+ class="ml-5"
12
+ size="mini"
13
+ @click="clearSelection"
14
+ >取消</el-button
15
+ >
16
+ </template>
17
+ </div>
18
+ <div :class="{'pb-10': $slots.tools || tools.length}" class=" flex justify-content-between align-items-center">
19
+ <slot name="tools">
20
+ <!-- <el-button-group> -->
21
+ <div>
22
+ <el-tooltip
23
+ v-for="(item, idx) in tools"
24
+ :key="idx"
25
+ :content="item.label"
26
+ placement="bottom"
27
+ effect="dark"
28
+ >
29
+ <el-button
30
+ size="mini"
31
+ type="primary"
32
+ plain
33
+ :icon="item.icon"
34
+ @click="handleToolsItem(item, idx)"
35
+ >
36
+ {{ item.label }}
37
+ </el-button>
38
+ </el-tooltip>
39
+ </div>
40
+ <!-- </el-button-group> -->
41
+ </slot>
6
42
  <el-tooltip
7
- v-for="(item, idx) in tools"
8
- :key="idx"
9
- :content="item.label"
43
+ class="ml-10"
44
+ content="刷新"
10
45
  placement="bottom"
11
46
  effect="dark"
12
47
  >
13
48
  <el-button
49
+ v-if="showRefresh"
14
50
  size="mini"
15
- :icon="item.icon"
16
- @click="handleToolsItem(item, idx)"
17
- >
18
- {{item.label}}
19
- </el-button>
20
- </el-tooltip>
21
- <el-tooltip content="刷新列表" placement="bottom" effect="dark">
22
- <el-button
23
- size="mini"
51
+ type="primary"
24
52
  @click="$emit('on-refresh')"
25
53
  icon="el-icon-refresh"
54
+ plain
26
55
  ></el-button>
27
56
  </el-tooltip>
28
57
  <el-popover
@@ -30,6 +59,7 @@
30
59
  popper-class="xn-table-box-tools__pop"
31
60
  class="ml-10"
32
61
  trigger="hover"
62
+ :hidden="!showColumn"
33
63
  >
34
64
  <el-scrollbar
35
65
  class="xn-table-box-tools__coll"
@@ -45,27 +75,16 @@
45
75
  </div>
46
76
  </el-scrollbar>
47
77
  <el-button
78
+ plain
48
79
  size="mini"
80
+ type="primary"
49
81
  icon="el-icon-setting"
50
82
  slot="reference"
51
83
  ></el-button>
52
84
  </el-popover>
53
- </el-button-group>
54
- </slot>
85
+ </div>
86
+ </div>
55
87
  </div>
56
- <!-- <el-button
57
- circle
58
- size="mini"
59
- @click="$emit('on-export')"
60
- icon="el-icon-files"
61
- ></el-button>
62
- <el-button
63
- circle
64
- size="mini"
65
- @click="$emit('on-refresh')"
66
- icon="el-icon-refresh"
67
- ></el-button> -->
68
-
69
88
  <el-table
70
89
  ref="table"
71
90
  :data="data"
@@ -74,6 +93,8 @@
74
93
  :border="border"
75
94
  :stripe="stripe"
76
95
  @row-click="singleElection"
96
+ @selection-change="selectionChange"
97
+ :class="{ 'disabled-all-selection': radio }"
77
98
  >
78
99
  <el-table-column
79
100
  v-if="selection && data.length"
@@ -82,7 +103,7 @@
82
103
  width="50px"
83
104
  align="center"
84
105
  ></el-table-column>
85
- <el-table-column v-bind="$attrs" v-if="radio" width="50px" align="center">
106
+ <el-table-column v-bind="$attrs" v-if="radio" width="60px" align="center">
86
107
  <template slot-scope="{ row }">
87
108
  <el-radio v-model="radioSelected" :label="row.id">&nbsp;</el-radio>
88
109
  </template>
@@ -105,11 +126,11 @@
105
126
  </slot>
106
127
  </el-table>
107
128
 
108
- <template v-if="!$utils.isEmpty(pageConfig)">
129
+ <template v-if="!$utils.isEmpty(page)">
109
130
  <xn-page
110
- :total="pageConfig.total"
111
- :page.sync="pageConfig.pageNum"
112
- :limit.sync="pageConfig.pageSize"
131
+ :total="page.total"
132
+ :pageNum.sync="page.pageNum"
133
+ :pageSize.sync="page.pageSize"
113
134
  @pagination="getList"
114
135
  layout="total, prev, pager, next, jumper"
115
136
  ></xn-page>
@@ -142,23 +163,25 @@ export default {
142
163
  stripe: Boolean,
143
164
  selection: Boolean,
144
165
  radio: Boolean,
145
-
146
166
  showPage: Boolean,
167
+ showRefresh: Boolean,
147
168
  pageLayout: {
148
169
  type: String,
149
170
  default: "total, prev, pager, next, jumper",
150
171
  },
151
- pageConfig: {
172
+ page: {
152
173
  type: Object,
153
174
  default: () => {},
154
175
  },
155
- index: Boolean,
176
+ index: { type: Boolean, default: true },
177
+ showColumn: Boolean,
156
178
  expand: Boolean,
157
179
  isTools: Boolean,
158
180
  },
159
181
  data() {
160
182
  return {
161
183
  radioSelected: "",
184
+ selectedData: [],
162
185
  };
163
186
  },
164
187
  computed: {},
@@ -172,7 +195,6 @@ export default {
172
195
  getList(val) {
173
196
  this.$emit("on-page", val);
174
197
  },
175
-
176
198
  singleElection(val) {
177
199
  if (!this.radio) return;
178
200
  this.radioSelected = val.id;
@@ -185,7 +207,20 @@ export default {
185
207
  handleChangeToolshow(item) {
186
208
  item.checked = item.checked === true ? false : true;
187
209
  this.$refs.table.doLayout();
188
- console.log(this.$root);
210
+ },
211
+ selectionChange(val) {
212
+ this.selectedData = val;
213
+ this.$emit("selection-change", val);
214
+ // this.$refs.table.get
215
+ },
216
+ toggleRowSelection(row, status) {
217
+ this.$refs.table.toggleRowSelection(row, status);
218
+ },
219
+ clearSelection() {
220
+ this.$refs.table.clearSelection();
221
+ },
222
+ doLayout() {
223
+ this.$refs.table.doLayout();
189
224
  },
190
225
  },
191
226
  };
@@ -6,6 +6,7 @@
6
6
  }"
7
7
  class="xn-upload xn-upload-main"
8
8
  action="###"
9
+ :limit="limit"
9
10
  :list-type="listType"
10
11
  v-bind="$attrs"
11
12
  :file-list.sync="fileList"
@@ -20,41 +21,37 @@
20
21
  <template v-if="listType === 'picture-card'">
21
22
  <div slot="trigger" class="upload-limit">
22
23
  <i class="el-icon el-icon-plus" />
23
- <span
24
- ><em>{{ fileList.length }}</em
25
- >/<em>{{ limit }}</em>
26
- </span>
27
24
  </div>
28
25
  </template>
29
26
  <template v-else>
30
27
  <slot>
31
- <el-button icon="el-icon-upload">编辑</el-button>
28
+ <el-button icon="el-icon-upload" :disabled="$attrs.disabled">上传</el-button>
32
29
  </slot>
33
30
  </template>
34
31
  <div
35
32
  slot="file"
36
33
  slot-scope="{ file }"
37
34
  class="xn-upload--slot"
38
- :class="{ 'upload-slot-idcard': listType === 'idcard' }"
35
+ v-if="listType === 'picture-card'"
39
36
  >
40
37
  <uploadPop :file="file" @on-download="handleDownload(file)"></uploadPop>
41
- <template v-if="isImage(file)">
42
- <el-image
43
- class="el-upload-list__item-thumbnail"
44
- :src="file.url"
45
- fit="cover"
46
- :lazy="true"
47
- />
48
- </template>
49
- <template v-else>
50
- <div class="xn-upload-list__item--file">
51
- <div class="annex">
52
- <i class="el-icon el-icon-folder" />
53
- <span class="label">附件</span>
38
+ <template v-if="$utils.isImg(file)">
39
+ <el-image
40
+ class="el-upload-list__item-thumbnail"
41
+ :src="file.url"
42
+ fit="cover"
43
+ :lazy="true"
44
+ />
45
+ </template>
46
+ <template v-else>
47
+ <div class="xn-upload-list__item-file">
48
+ <div class="annex">
49
+ <i class="el-icon el-icon-folder" />
50
+ <span class="label">附件</span>
51
+ </div>
52
+ <div class="file-name">{{ file.name }}</div>
54
53
  </div>
55
- <div class="file-name">{{ file.accessoryName }}</div>
56
- </div>
57
- </template>
54
+ </template>
58
55
  <div v-if="file.status === 'uploading'" class="process">
59
56
  <el-progress
60
57
  :status="file.percentage === 100 ? 'success' : null"
@@ -65,21 +62,21 @@
65
62
  </div>
66
63
  <span class="el-upload-list__item-actions">
67
64
  <span
68
- v-if="isImage(file)"
65
+ v-if="$utils.isImg(file)"
69
66
  class="el-upload-list__item-preview"
70
67
  @click="handlePictureCardPreview(file)"
71
68
  >
72
69
  <i class="fz-16 el-icon-zoom-in" />
73
70
  </span>
74
71
  <span
75
- class="el-upload-list__item-delete icon"
72
+ class="el-upload-list__item-delete icon ml-5"
76
73
  @click="handleDownload(file, fileList)"
77
74
  >
78
75
  <i class="fz-16 el-icon-download" />
79
76
  </span>
80
77
  <span
81
78
  v-if="!$attrs.disabled && !preview"
82
- class="el-upload-list__item-delete icon"
79
+ class="el-upload-list__item-delete icon ml-5"
83
80
  @click="handleRemove(file, fileList)"
84
81
  >
85
82
  <i class="fz-16 el-icon-delete" />
@@ -103,7 +100,7 @@ import axios from "axios";
103
100
  import uploadPop from "./upload-pop.vue";
104
101
  export default {
105
102
  name: "XnUpload",
106
- inheritAttrs: true,
103
+ inheritAttrs: false,
107
104
  components: {
108
105
  uploadPop,
109
106
  ElImageViewer,
@@ -180,11 +177,6 @@ export default {
180
177
  return Math.floor(num);
181
178
  };
182
179
  },
183
- isImage() {
184
- return (file) => {
185
- return file.imgFlag;
186
- };
187
- },
188
180
  },
189
181
  watch: {
190
182
  fileList: {
@@ -200,7 +192,6 @@ export default {
200
192
  },
201
193
  },
202
194
  created() {
203
- console.log(this.$attrs);
204
195
  },
205
196
  beforeDestroy() {
206
197
  this.$emit("update:fileList", []);
@@ -224,7 +215,7 @@ export default {
224
215
  if (compress) {
225
216
  size = compress;
226
217
  } else {
227
- size = file.size > _maxSize ? _maxSize / 1024 : file.size
218
+ size = file.size > _maxSize ? _maxSize / 1024 : file.size;
228
219
  }
229
220
  return new Promise((resolve) => {
230
221
  imageConversion["compressAccurately"](file, size).then((result) => {
@@ -246,22 +237,23 @@ export default {
246
237
  },
247
238
  async onHttpUpload(file) {
248
239
  const formData = new FormData();
249
- let result = null;
250
- if (this.$utils.isImg(file.file.name)) {
251
- result = await this.handleCompress(file.file);
252
- var newFile = new window.File([result], file.file.name, {
253
- type: file.file.type,
254
- });
255
- }
256
- const _file = result ? newFile : file.file;
240
+ // let result = null;
241
+ // if (this.$utils.isImg(file.file.name)) {
242
+ // result = await this.handleCompress(file.file);
243
+ // var newFile = new window.File([result], file.file.name, {
244
+ // type: file.file.type,
245
+ // });
246
+ // }
247
+ const _file = file.file;
257
248
  formData.append("file", _file);
258
249
 
259
250
  axios({
260
251
  method: "post",
261
- url: this.$XN.uploadUrl || '',
252
+ url: this.$XN.uploadUrl || "",
262
253
  data: formData,
263
254
  headers: {
264
255
  "Content-Type": "application/x-www-form-urlencoded",
256
+ xnToken: this.$storage.get("xnToken"),
265
257
  },
266
258
  onUploadProgress(progress) {
267
259
  const _progress = Math.round(
@@ -271,11 +263,10 @@ export default {
271
263
  },
272
264
  })
273
265
  .then((res) => {
274
- const { accessoryName, accessorySize, ext, imgFlag, url } =
275
- res.data.data;
266
+ const { name, size, ext, imgFlag, url } = res.data.data;
276
267
  var obj = {};
277
- obj.accessoryName = accessoryName;
278
- obj.accessorySize = accessorySize;
268
+ obj.name = name;
269
+ obj.size = size;
279
270
  obj.ext = ext;
280
271
  obj.imgFlag = imgFlag;
281
272
  obj.url = url;
@@ -303,7 +294,7 @@ export default {
303
294
  },
304
295
 
305
296
  onExceed() {
306
- this.$message.warning(`上传总数限制为【${this.limit}】个,请删除后上传`);
297
+ this.$message.warning(`上传总数不能超过【${this.limit}】个`);
307
298
  },
308
299
  handlePictureCardPreview(file) {
309
300
  this.isShowImageView = true;
@@ -335,7 +326,6 @@ export default {
335
326
  });
336
327
  }
337
328
  this.$emit("update:fileList", fileList);
338
- // this.$emit('on-change', fileList.map(item => item.url).join(','))
339
329
  },
340
330
  closeViewer() {
341
331
  this.isShowImageView = false;
@@ -2,12 +2,12 @@
2
2
  <el-popover width="300" trigger="hover">
3
3
  <el-form label-width="80px" size="mini">
4
4
  <el-form-item label="文件名">
5
- <div :title="file.accessoryName" class="tip-filename">
6
- {{ file.accessoryName }}
5
+ <div :title="file.name" class="tip-filename">
6
+ {{ file.name }}
7
7
  </div>
8
8
  </el-form-item>
9
9
  <el-form-item label="文件大小">
10
- {{ $format.bytesToSize(file.accessorySize) }}
10
+ {{ $format.bytesToSize(file.size) }}
11
11
  </el-form-item>
12
12
  <el-form-item label="文件格式">
13
13
  {{ file.ext }}
package/src/index.js CHANGED
@@ -30,7 +30,6 @@ const components = [
30
30
  const version = require('../package.json').version
31
31
 
32
32
  const install = function (Vue) {
33
- console.log(Vue.prototype);
34
33
  if (install.installed) return
35
34
  if (!Vue.prototype.$ELEMENT) throw new Error('缺失 element-ui,请进行安装')
36
35
  install.installed = true
@@ -39,7 +38,7 @@ const install = function (Vue) {
39
38
  })
40
39
 
41
40
  Vue.prototype.$XN = {
42
- uploadUrl: ''
41
+ uploadUrl: 'https://gateway.dev.xianniu.cn/file-server/oss/uploadFile'
43
42
  }
44
43
  Vue.prototype.$utils = Utils.$utils
45
44
  Vue.prototype.$reg = Utils.$reg
@@ -18,12 +18,14 @@ const isEmpty = function (val) {
18
18
  /**
19
19
  * 判断是否是图片格式
20
20
  */
21
- const isImg = (filePath) => {
22
- if (typeof filePath !== 'string' || !filePath) return
21
+ const isImg = (file) => {
22
+ const { url } = file
23
+ if (typeof url !== 'string' || !url) return
23
24
  var strFilter = '.jpeg|.gif|.jpg|.png|.bmp|.pic|.svg|'
24
- if (filePath.indexOf('.') > -1) {
25
- var p = filePath.lastIndexOf('.')
26
- var strPostfix = filePath.substring(p, filePath.length) + '|'
25
+ if (file.imgFlag) return true
26
+ if (url.indexOf('.') > -1) {
27
+ var p = url.lastIndexOf('.')
28
+ var strPostfix = url.substring(p, url.length) + '|'
27
29
  strPostfix = strPostfix.toLowerCase()
28
30
  if (strFilter.indexOf(strPostfix) > -1) {
29
31
  return true
@@ -66,7 +68,7 @@ const download = (params = { name: '', url: '' }) => {
66
68
  const { url, name } = _params
67
69
  var x = new XMLHttpRequest()
68
70
  x.open('GET', url, true)
69
- x.responseType = 'blob'
71
+ // x.responseType = 'blob'
70
72
  x.onload = function () {
71
73
  // 会创建一个 DOMString,其中包含一个表示参数中给出的对象的URL。这个 URL 的生命周期和创建它的窗口中的 document 绑定。这个新的URL 对象表示指定的 File 对象或 Blob 对象。
72
74
  var url = window.URL.createObjectURL(x.response)
@@ -1,90 +0,0 @@
1
- <template>
2
- <el-dialog
3
- :visible.sync="dialogVisible"
4
- v-bind="$attrs"
5
- v-on="$listeners"
6
- :before-close="onBeforeClose"
7
- :width="$attrs.width ? $attrs.width : _width"
8
- >
9
- <slot />
10
- <span slot="footer" class="text-right">
11
- <slot name="footer">
12
- <el-button @click="onClose">取消</el-button>
13
- <el-button
14
- v-if="$attrs['show-confirm']"
15
- type="primary"
16
- @click="onConfirm"
17
- >{{ $attrs["confirm-text"] || "提交" }}</el-button
18
- >
19
- </slot>
20
- </span>
21
- </el-dialog>
22
- </template>
23
-
24
- <script>
25
- export default {
26
- name: "XnDialog",
27
- inheritAttrs: false,
28
- props: {
29
- show: {
30
- type: Boolean,
31
- default: false,
32
- },
33
- beforeClose: {
34
- type: Function,
35
- default: () => {},
36
- },
37
- },
38
- created() {
39
- console.log(this);
40
- },
41
- computed: {
42
- _width() {
43
- const arr = [
44
- { label: "mini", value: "320px" },
45
- { label: "small", value: "560px" },
46
- { label: "medium", value: "720px" },
47
- { label: "large", value: "960px" },
48
- ];
49
-
50
- var width = "";
51
- arr.forEach((item) => {
52
- if (item.label === this.$attrs.size || this.size) {
53
- width = item.value;
54
- }
55
- });
56
- return width;
57
- },
58
- dialogVisible: {
59
- get() {
60
- return this.show;
61
- },
62
- set(val) {
63
- console.log('val: ', val);
64
- this.$emit("on-visible", val);
65
- },
66
- },
67
- },
68
- data() {
69
- return {};
70
- },
71
- methods: {
72
- onClose() {
73
- this.$emit("update:show", false);
74
- },
75
- onBeforeClose(){
76
- if(this.beforeClose && typeof beforeClose === 'function'){
77
- return this.beforeClose()
78
- }else{
79
- return this.onClose()
80
- }
81
- },
82
- onConfirm() {
83
- this.$emit("on-confirm");
84
- },
85
- },
86
- };
87
- </script>
88
-
89
- <style>
90
- </style>