qtsk-vue3 0.0.29 → 0.0.31

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,10 +1,12 @@
1
1
  <template>
2
2
  <el-select
3
+ ref="selectRef"
3
4
  v-model="selectValue"
4
5
  :placeholder="placeholder"
5
6
  v-bind="$attrs"
6
7
  :teleported="false"
7
8
  :loading="loading"
9
+ v-limitLength="maxLength"
8
10
  clearable
9
11
  filterable
10
12
  remote
@@ -28,7 +30,6 @@ import { ElSelect, ElOption } from 'element-plus'
28
30
  import '../../style/root.css'
29
31
 
30
32
  const loading = ref(false)
31
-
32
33
  defineOptions({
33
34
  name: 'SelectRemote'
34
35
  })
@@ -51,14 +52,25 @@ const props = defineProps({
51
52
  list: {
52
53
  type: Array,
53
54
  default: () => ([])
54
- }
55
+ },
56
+ maxLength: Number
55
57
  })
56
58
  const selectValue = defineModel('modelValue', { default: '', type: [Number, String, Array] })
57
59
  const options = ref([])
60
+
61
+ const vLimitLength = {
62
+ mounted: function (el, binding) {
63
+ if (!props.maxLength) return false
64
+ const input = el.getElementsByTagName('input')[0]
65
+ if (input) {
66
+ input.setAttribute('maxlength', binding.value)
67
+ }
68
+ }
69
+ }
58
70
  const remoteMethod = (query) => {
59
71
  if (query) {
60
- props.remoteMethod(query)
61
72
  selectValue.value = query
73
+ props.remoteMethod(query)
62
74
  } else {
63
75
  options.value = []
64
76
  }
@@ -1,15 +1,18 @@
1
1
  <template>
2
2
  <div class="normalClass">
3
3
  <el-upload
4
- class="upload-demo"
4
+ class="upload-demo"
5
+ ref="uploadRef"
5
6
  drag
6
7
  accept=".xls,.xlsx"
7
8
  :name="name"
8
9
  :limit="limit"
9
10
  :file-list="fileListRef"
10
- :before-upload="beforeUpload"
11
11
  :on-success="handleSuccess"
12
+ :on-change="handleChange"
12
13
  :headers="headers"
14
+ :disabled="fileListRef.length === 0 ? false : true"
15
+ :auto-upload="false"
13
16
  :action="url">
14
17
  <Icons :type="'Plus'" :size="30"></Icons>
15
18
  <div class="el-upload__text">
@@ -21,7 +24,7 @@
21
24
  </template>
22
25
 
23
26
  <script setup>
24
- import { ref } from 'vue'
27
+ import { ref, watch } from 'vue'
25
28
  import { ElUpload } from 'element-plus'
26
29
  import Icons from '../Icons/index.vue'
27
30
  import { Message } from '../Message/index.js'
@@ -43,37 +46,45 @@ defineProps({
43
46
  })
44
47
 
45
48
  const fileListRef = ref([])
49
+ const uploadRef = ref(null)
46
50
  const emits = defineEmits(['successUpload'])
47
- const beforeUpload = (file) => {
51
+
52
+ const handleChange = (file) => {
53
+ const files = fileListRef.value || []
54
+ if (files.length) return false
48
55
  const isAllowedType = /\.(xls|xlsx)$/.test(file.name);
49
56
  const isAllowedSize = file.size / 1024 / 1024 < 5;;
50
-
51
57
  if (!isAllowedType) {
52
- Message.error('只能上传xls,xlsx文件!');
58
+ fileListRef.value = []
59
+ return Message.error('只能上传xls,xlsx文件!');
53
60
  }
54
61
  if (!isAllowedSize) {
55
- Message.error('上传文件不能超过 5M');
62
+ fileListRef.value = []
63
+ return Message.error('上传文件不能超过 5M');
56
64
  }
57
- return isAllowedType && isAllowedSize;
65
+ const size = (file.size / 1024).toFixed(2)
66
+ const name = `${file.name} (${size}K)`
67
+ files.push(
68
+ {
69
+ name
70
+ }
71
+ );
72
+ fileListRef.value = files
73
+ const uploadElement = document.getElementsByClassName('el-upload')[0]
74
+ uploadElement.style.display = 'none'
58
75
  }
59
-
60
76
  const handleSuccess = (res, file, fileList) => {
61
77
  if (res.code === 200) {
62
- const size = (file.size / 1024).toFixed(2)
63
- const name = `${file.name} (${size}K)`
64
- console.log('fileList.value1', fileListRef.value)
65
- const files = fileListRef.value || []
66
- files.push(
67
- {
68
- name
69
- }
70
- );
71
- fileListRef.value = files
72
78
  emits('successUpload', res)
73
79
  } else {
74
80
  Message.error(res.msg || res.data.msg || res.message || '上传失败')
75
81
  }
76
82
  }
83
+
84
+ defineExpose({
85
+ handleUpload: () => { uploadRef.value.submit() },
86
+ getFileList: () => fileListRef.value.length
87
+ })
77
88
  </script>
78
89
 
79
90
  <style lang="less" scoped>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qtsk-vue3",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "description": "vue3版组件库",
5
5
  "main": "./package/index.js",
6
6
  "scripts": {