widget.qw 1.0.75 → 1.0.77

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,7 +1,7 @@
1
1
  {
2
2
  "name": "widget.qw",
3
3
  "private": false,
4
- "version": "1.0.75",
4
+ "version": "1.0.77",
5
5
  "description": "marqstree Vue3组件库",
6
6
  "main": "build/widget.qw.es.js",
7
7
  "keywords": [
@@ -3,10 +3,9 @@
3
3
  label-class="label" :placeholder="props.placeholder">
4
4
  <template #input>
5
5
  <div class="file-box">
6
- <van-uploader v-model="files" :max-count="props.max" :afterRead="onAfterRead" :disabled="isDisabled"
7
- :accept="props.accept" upload-icon="plus" :deletable="!isDisabled"
8
- :before-delete="onBeforeDelete"
9
- @click-preview="onClickPreview" />
6
+ <van-uploader v-model="files" :multiple="props.multiple" :max-count="maxCount" :afterRead="onAfterRead"
7
+ :disabled="isDisabled" :accept="props.accept" upload-icon="plus" :deletable="!isDisabled"
8
+ :before-delete="onBeforeDelete" @click-preview="onClickPreview" />
10
9
  </div>
11
10
  </template>
12
11
  </van-field>
@@ -30,6 +29,10 @@ const props = defineProps({
30
29
  type: Boolean,
31
30
  default: false
32
31
  },
32
+ maxCount: {
33
+ type: Number,
34
+ default: 1000
35
+ },
33
36
  required: {
34
37
  type: Boolean,
35
38
  default: false
@@ -61,35 +64,59 @@ const modelValue = useVModel(props, 'modelValue', emit)
61
64
  const { isRequired, isReadonly, isGone, isDisabled } = util.props2auth(props)
62
65
 
63
66
  const files = ref([])
67
+ const maxCount = computed(() => {
68
+ if (props.multiple)
69
+ return props.maxCount
70
+ else
71
+ return 1
72
+ })
64
73
 
65
74
  onMounted(() => {
66
75
 
67
76
  })
68
77
 
69
- const onClickPreview=(e)=>{
78
+ const onClickPreview = (e) => {
70
79
  let url = (e.url || '')
71
- if(url.includes('.jpg') || url.includes('.png') || url.includes('.jpeg'))
80
+ if (url.includes('.jpg') || url.includes('.png') || url.includes('.jpeg'))
72
81
  return
73
82
 
74
83
  window.location.href = e.url
75
84
  }
76
85
 
77
- const onAfterRead = async (file) => {
78
- console.log(file)
79
- let params = {
80
- file: file.file
81
- }
86
+ const onAfterRead = async (e) => {
87
+ console.log('onAfterRead', e)
88
+
89
+ if (props.multiple) {
90
+ if (e && e.length > 0) {
91
+ for (var i = 0; i < e.length; i++) {
92
+ let params = {
93
+ file: e[i].file
94
+ }
95
+
96
+ let res = await util.file_upload(params)
97
+ if (res.code == 200) {
98
+ modelValue.value = [...(modelValue.value || []), res.data]
99
+ }
100
+ }
101
+
102
+ return Promise.resolve(e)
103
+ }
104
+ } else {
105
+ let params = {
106
+ file: e.file
107
+ }
82
108
 
83
- return util.file_upload(params).then(res => {
84
- if (props.multiple)
85
- modelValue.value = [...(modelValue.value || []), res.data]
86
- else
109
+ let res = await util.file_upload(params)
110
+ if (res.code == 200) {
87
111
  modelValue.value = res.data
88
- return Promise.resolve(file)
89
- })
112
+ return Promise.resolve(e)
113
+ }
114
+ }
90
115
  }
91
116
 
92
117
  const onBeforeDelete = (e) => {
118
+ console.log('onBeforeDelete', e)
119
+
93
120
  if (props.multiple) {
94
121
  let newUrls = props.modelValue.filter(item => {
95
122
  return item != e.url
@@ -3,12 +3,15 @@
3
3
  :placeholder="props.placeholder">
4
4
  <template #input>
5
5
  <div class="image-box">
6
- <van-uploader v-if="props.capture" v-model="files" :max-count="props.max" :capture="props.capture"
7
- accept="image/jpeg,image/png" :disabled="isDisabled" :deletable="!isRequired && !isDisabled"
8
- :afterRead="onAfterRead" :before-delete="onBeforeDelete" :show-upload="!isReadonly"/>
9
- <van-uploader v-else v-model="files" :max-count="props.max" accept="image/jpeg,image/png"
10
- :disabled="isDisabled" :deletable="!isReadonly && !isDisabled" :afterRead="onAfterRead"
11
- :before-delete="onBeforeDelete" :show-upload="!isReadonly"/>
6
+ <van-uploader v-if="props.capture && (!isReadonly && !isDisabled)" v-model="files" :max-count="props.max"
7
+ :capture="props.capture" accept="image/jpeg,image/png" :disabled="isDisabled"
8
+ :deletable="!isRequired && !isDisabled" :afterRead="onAfterRead" :before-delete="onBeforeDelete"
9
+ :show-upload="!isReadonly" />
10
+ <van-uploader v-if="!props.capture && (!isReadonly && !isDisabled)" v-model="files" :max-count="props.max"
11
+ accept="image/jpeg,image/png" :disabled="isDisabled" :deletable="!isReadonly && !isDisabled"
12
+ :afterRead="onAfterRead" :before-delete="onBeforeDelete" :show-upload="!isReadonly" />
13
+ <img class="cover" v-if="isReadonly || isDisabled" v-for="(cover, i) in previews" :key="i" :src="cover" @click="onPreview(i)" />
14
+ <van-icon v-if="modelValue.length>props.maxPreview && (isReadonly || isDisabled)" name="ellipsis" @click="onToggleMore"/>
12
15
  </div>
13
16
  </template>
14
17
  </van-field>
@@ -18,6 +21,7 @@
18
21
  import { ref, computed, onMounted, defineProps, defineEmits, watch } from "vue"
19
22
  import util from "@/util"
20
23
  import { useVModel } from "@vueuse/core"
24
+ import { showImagePreview } from 'vant';
21
25
 
22
26
  const props = defineProps({
23
27
  modelValue: {
@@ -50,7 +54,7 @@ const props = defineProps({
50
54
  },
51
55
  max: {
52
56
  type: Number,
53
- default: 1000
57
+ default: 10000
54
58
  },
55
59
  rules: {
56
60
  type: Array,
@@ -59,12 +63,26 @@ const props = defineProps({
59
63
  auth: {
60
64
  type: String,
61
65
  default: ''
66
+ },
67
+ maxPreview: {
68
+ type: Number,
69
+ default: 1
62
70
  }
63
71
  })
64
72
  const emit = defineEmits(['update:modelValue'])
65
73
  const modelValue = useVModel(props, 'modelValue', emit)
66
74
  const { isRequired, isReadonly, isGone, isDisabled } = util.props2auth(props)
67
75
  const files = ref([])
76
+ const isPreviewMore=ref(false)
77
+ const previews=computed(()=>{
78
+ if(!modelValue.value || modelValue.value.length<1)
79
+ return []
80
+
81
+ if(props.maxPreview > modelValue.value.length || isPreviewMore.value)
82
+ return modelValue.value
83
+
84
+ return modelValue.value.slice(0, props.maxPreview)
85
+ })
68
86
 
69
87
  onMounted(() => {
70
88
 
@@ -102,6 +120,14 @@ const onBeforeDelete = (e) => {
102
120
  return Promise.resolve(e)
103
121
  }
104
122
 
123
+ const onPreview = (i) => {
124
+ showImagePreview({images:modelValue.value, startPosition:i})
125
+ }
126
+
127
+ const onToggleMore=()=>{
128
+ isPreviewMore.value = !isPreviewMore.value
129
+ }
130
+
105
131
  watch(() => props.modelValue,
106
132
  (newVal, oldVal) => {
107
133
  if (!props.modelValue || props.modelValue.length < 1) {
@@ -123,23 +149,12 @@ watch(() => props.modelValue,
123
149
  </script>
124
150
 
125
151
  <style lang="scss" scoped>
126
- .widget {
127
- text-align: center;
128
-
129
- .btn {
130
- position: fixed;
131
- bottom: 1rem;
132
- left: 0;
133
- right: 0;
134
- margin: auto auto;
135
- color: white;
136
- font-size: 14px;
137
- background: rgba(58, 136, 255, 1);
138
- padding: 8px 35px;
139
- width: 100px;
140
- text-align: center;
141
- display: inline-block;
142
- border-radius: 2px;
152
+
153
+ .image-box {
154
+
155
+ .cover {
156
+ width: 80px;
157
+ height: 80px;
158
+ }
143
159
  }
144
- }
145
160
  </style>
@@ -9,7 +9,8 @@ import { onMounted, reactive, watch } from "vue";
9
9
 
10
10
  const data = reactive({
11
11
  auth:'require',
12
- urls: ['http://www.zjpsjdsb.online/static/QxI3PBaT.pdf','http://www.zjpsjdsb.online/static/gxm6QYXR.png']
12
+ // url: 'http://www.zjpsjdsb.online/static/QxI3PBaT.pdf'
13
+ urls: ['http://www.zjpsjdsb.online/static/gxm6QYXR.png','http://www.zjpsjdsb.online/static/gxm6QYXR.png']
13
14
  })
14
15
 
15
16
  watch(()=>data.url,(newVal,oldVal)=>{
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="page">
3
- <widget-qw-images-picker label="图片列表" v-model="data.urls" :auth="data.auth" />
3
+ <widget-qw-images-picker label="图片列表" v-model="data.urls" :auth="data.auth" maxPreview=1 />
4
4
  </div>
5
5
  </template>
6
6
 
@@ -9,7 +9,7 @@ import { onMounted, reactive, watch } from "vue";
9
9
 
10
10
  const data = reactive({
11
11
  auth:'readonly',
12
- urls: ['http://www.zjpsjdsb.online/static//HrMi9Q2J.png']
12
+ urls: ['http://www.zjpsjdsb.online/static//HrMi9Q2J.png','http://www.zjpsjdsb.online/static//HrMi9Q2J.png','http://www.zjpsjdsb.online/static//HrMi9Q2J.png','http://www.zjpsjdsb.online/static//HrMi9Q2J.png','http://www.zjpsjdsb.online/static//HrMi9Q2J.png','http://www.zjpsjdsb.online/static//HrMi9Q2J.png']
13
13
  })
14
14
 
15
15
  watch(()=>data.url,(newVal,oldVal)=>{