af-mobile-client-vue3 1.0.69 → 1.0.71

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,185 +1,183 @@
1
- <script setup lang="ts">
2
- import {
3
- Cell as VanCell,
4
- CellGroup as VanCellGroup,
5
- Checkbox as VanCheckbox,
6
- CheckboxGroup as VanCheckboxGroup,
7
- Field as VanField,
8
- Popup as VanPopup,
9
- Search as VanSearch
10
- } from 'vant'
11
- import {computed, reactive, ref, watch, defineProps, defineEmits, defineModel} from 'vue'
12
-
13
- const props = defineProps({
14
- columns: {
15
- type: Array,
16
- default() {
17
- return []
18
- },
19
- },
20
- selectValue: {
21
- type: Array,
22
- default() {
23
- return []
24
- },
25
- },
26
- option: {
27
- type: Object,
28
- default() {
29
- return { text: 'label', value: 'value' }
30
- },
31
- },
32
- // 是否支持搜索
33
- isSearch: {
34
- type: Boolean,
35
- default: true
36
- },
37
- })
38
- const emits = defineEmits(['input', 'confirm', 'change', 'cancel'])
39
- const show = ref(false)
40
- const searchVal = ref('')
41
- const columnsData = ref([])
42
- const checkboxValue = ref(JSON.parse(JSON.stringify(props.selectValue)))
43
- const checkedAll = ref(false)
44
- const resultValue = defineModel()
45
- const checkboxGroup = ref()
46
- const checkboxes = ref()
47
- function search(val) {
48
- if (val) {
49
- columnsData.value = props.columns.filter((item) => {
50
- return item[props.option.text].includes(val)
51
- })
52
- }
53
- else {
54
- columnsData.value = JSON.parse(JSON.stringify(props.columns))
55
- }
56
- }
57
- function getData(val) {
58
- const res = props.columns.filter((item) => {
59
- return val.includes(item[props.option.value])
60
- })
61
- return res
62
- }
63
- function onConfirm() {
64
- console.log(checkboxValue.value)
65
- resultValue.value = checkboxValue.value
66
- show.value = !show.value
67
- emits('confirm', resultValue.value, getData(resultValue.value))
68
- }
69
- function change(val) {
70
- emits('change', val, getData(resultValue.value))
71
- }
72
- function cancel() {
73
- show.value = !show.value
74
- emits('cancel', resultValue.value)
75
- }
76
- function toggle(item, index) {
77
- // 假设 checkboxValue 是一个对象,我们通过 index 来切换对应 checkbox 的值
78
- let idx = checkboxValue.value.indexOf(item[props.option.value])
79
- if(idx !== -1) {
80
- checkboxValue.value.splice(idx,1)
81
- }else{
82
- checkboxValue.value.push(item[props.option.value])
83
- }
84
- }
85
- function toggleAll() {
86
- // 遍历 checkboxValue 并设置所有 checkbox 的值为 checkedAll 的值
87
- if(checkedAll.value){
88
- checkboxValue.value = columnsData.value.map( item => item[props.option.value])
89
- }else{
90
- checkboxValue.value = []
91
- }
92
- }
93
- function showPopu(disabled) {
94
- columnsData.value = JSON.parse(JSON.stringify(props.columns))
95
- if (disabled !== undefined && disabled !== false)
96
- return false
97
- else
98
- show.value = !show.value
99
- }
100
- watch(() => columnsData.value, (newVal, _oldVal) => {
101
- checkedAll.value = newVal.length && newVal.length === checkboxValue.value.length
102
- })
103
- watch(() => checkboxValue.value.length, (newVal, _oldVal) => {
104
- checkedAll.value = newVal && newVal === columnsData.value.length
105
- })
106
- const resultLabel = computed(()=>{
107
- const res = props.columns.filter((item) => {
108
- return resultValue.value.includes(item[props.option.value])
109
- }).map( item => item[props.option.text])
110
- return res.join(',')
111
- })
112
- </script>
113
-
114
- <template>
115
- <div class="dh-field">
116
- <VanField
117
- v-model="resultLabel"
118
- v-bind="$attrs"
119
- readonly
120
- :border="false"
121
- :is-link="$attrs.disabled === undefined"
122
- error-message-align="right"
123
- @click="showPopu($attrs.disabled)"
124
- />
125
- <VanPopup v-model:show="show" position="bottom">
126
- <div class="van-picker__toolbar">
127
- <button type="button" class="van-picker__cancel" @click="cancel">
128
- 取消
129
- </button>
130
- <div class="van-ellipsis van-picker__title">
131
- {{ $attrs.label }}
132
- </div>
133
- <button type="button" class="van-picker__confirm" @click="onConfirm">
134
- 确认
135
- </button>
136
- </div>
137
- <div style="max-height:264px; overflow-y:auto;">
138
- <van-search
139
- v-if="props.isSearch"
140
- v-model="searchVal"
141
- placeholder="搜索"
142
- @update:modelValue="search"
143
- @cancel="search"
144
- />
145
- <VanCell title="全选">
146
- <template #right-icon>
147
- <VanCheckbox v-model="checkedAll" name="all" @click="toggleAll" />
148
- </template>
149
- </VanCell>
150
- <VanCheckboxGroup ref="checkboxGroup" v-model="checkboxValue" @change="change">
151
- <VanCellGroup>
152
- <VanCell
153
- v-for="(item, index) in columnsData"
154
- :key="item[props.option.value]"
155
- :title="item[props.option.text]"
156
- clickable
157
- @click="toggle(item, index)"
158
- >
159
- <template #right-icon>
160
- <VanCheckbox ref="checkboxes" :name="item[props.option.value]" @click.stop/>
161
- </template>
162
- </VanCell>
163
- </VanCellGroup>
164
- </VanCheckboxGroup>
165
- </div>
166
- </VanPopup>
167
- </div>
168
- </template>
169
-
170
- <style lang="less" scoped>
171
- .dh-field {
172
- width: 100%;
173
- padding: 0;
174
- background:#fff;
175
- .dh-cell.van-cell {
176
- padding: 10px 0;
177
- }
178
- .dh-cell.van-cell--required::before {
179
- left: -8px;
180
- }
181
- .van-popup {
182
- border-radius: 20px 20px 0 0;
183
- }
184
- }
185
- </style>
1
+ <script setup lang="ts">
2
+ import {
3
+ Cell as VanCell,
4
+ CellGroup as VanCellGroup,
5
+ Checkbox as VanCheckbox,
6
+ CheckboxGroup as VanCheckboxGroup,
7
+ Field as VanField,
8
+ Popup as VanPopup,
9
+ Search as VanSearch,
10
+ } from 'vant'
11
+ import { computed, defineEmits, defineModel, defineProps, ref, watch } from 'vue'
12
+
13
+ const props = defineProps({
14
+ columns: {
15
+ type: Array,
16
+ default() {
17
+ return []
18
+ },
19
+ },
20
+ selectValue: {
21
+ type: Array,
22
+ default() {
23
+ return []
24
+ },
25
+ },
26
+ option: {
27
+ type: Object,
28
+ default() {
29
+ return { text: 'label', value: 'value' }
30
+ },
31
+ },
32
+ // 是否支持搜索
33
+ isSearch: {
34
+ type: Boolean,
35
+ default: true,
36
+ },
37
+ })
38
+ const emits = defineEmits(['input', 'confirm', 'change', 'cancel'])
39
+ const show = ref(false)
40
+ const searchVal = ref('')
41
+ const columnsData = ref([])
42
+ const checkboxValue = ref(JSON.parse(JSON.stringify(props.selectValue)))
43
+ const checkedAll = ref(false)
44
+ const resultValue = defineModel()
45
+ const checkboxGroup = ref()
46
+ const checkboxes = ref()
47
+ function search(val) {
48
+ if (val) {
49
+ columnsData.value = props.columns.filter((item) => {
50
+ return item[props.option.text].includes(val)
51
+ })
52
+ }
53
+ else {
54
+ columnsData.value = JSON.parse(JSON.stringify(props.columns))
55
+ }
56
+ }
57
+ function getData(val) {
58
+ const res = props.columns.filter((item) => {
59
+ return val.includes(item[props.option.value])
60
+ })
61
+ return res
62
+ }
63
+ function onConfirm() {
64
+ resultValue.value = checkboxValue.value
65
+ show.value = !show.value
66
+ emits('confirm', resultValue.value, getData(resultValue.value))
67
+ }
68
+ function change(val) {
69
+ emits('change', val, getData(resultValue.value))
70
+ }
71
+ function cancel() {
72
+ show.value = !show.value
73
+ emits('cancel', resultValue.value)
74
+ }
75
+ function toggle(item, _index) {
76
+ // 假设 checkboxValue 是一个对象,我们通过 index 来切换对应 checkbox 的值
77
+ const idx = checkboxValue.value.indexOf(item[props.option.value])
78
+ if (idx !== -1)
79
+ checkboxValue.value.splice(idx, 1)
80
+ else
81
+ checkboxValue.value.push(item[props.option.value])
82
+ }
83
+ function toggleAll() {
84
+ // 遍历 checkboxValue 并设置所有 checkbox 的值为 checkedAll 的值
85
+ if (checkedAll.value)
86
+ checkboxValue.value = columnsData.value.map(item => item[props.option.value])
87
+
88
+ else
89
+ checkboxValue.value = []
90
+ }
91
+ function showPopu(disabled) {
92
+ columnsData.value = JSON.parse(JSON.stringify(props.columns))
93
+ if (disabled !== undefined && disabled !== false)
94
+ return false
95
+ else
96
+ show.value = !show.value
97
+ }
98
+ watch(() => columnsData.value, (newVal, _oldVal) => {
99
+ checkedAll.value = newVal.length && newVal.length === checkboxValue.value.length
100
+ })
101
+ watch(() => checkboxValue.value.length, (newVal, _oldVal) => {
102
+ checkedAll.value = newVal && newVal === columnsData.value.length
103
+ })
104
+ const resultLabel = computed(() => {
105
+ const res = props.columns.filter((item) => {
106
+ return (resultValue.value as unknown as string[]).includes(item[props.option.value])
107
+ }).map(item => item[props.option.text])
108
+ return res.join(',')
109
+ })
110
+ </script>
111
+
112
+ <template>
113
+ <div class="dh-field">
114
+ <VanField
115
+ v-model="resultLabel"
116
+ v-bind="$attrs"
117
+ readonly
118
+ :border="false"
119
+ :is-link="$attrs.disabled === undefined"
120
+ error-message-align="right"
121
+ @click="showPopu($attrs.readonly)"
122
+ />
123
+ <VanPopup v-model:show="show" position="bottom">
124
+ <div class="van-picker__toolbar">
125
+ <button type="button" class="van-picker__cancel" @click="cancel">
126
+ 取消
127
+ </button>
128
+ <div class="van-ellipsis van-picker__title">
129
+ {{ $attrs.label }}
130
+ </div>
131
+ <button type="button" class="van-picker__confirm" @click="onConfirm">
132
+ 确认
133
+ </button>
134
+ </div>
135
+ <div style="max-height:264px; overflow-y:auto;">
136
+ <VanSearch
137
+ v-if="props.isSearch"
138
+ v-model="searchVal"
139
+ placeholder="搜索"
140
+ @update:model-value="search"
141
+ @cancel="search"
142
+ />
143
+ <VanCell title="全选">
144
+ <template #right-icon>
145
+ <VanCheckbox v-model="checkedAll" name="all" @click="toggleAll" />
146
+ </template>
147
+ </VanCell>
148
+ <VanCheckboxGroup ref="checkboxGroup" v-model="checkboxValue" @change="change">
149
+ <VanCellGroup>
150
+ <VanCell
151
+ v-for="(item, index) in columnsData"
152
+ :key="item[props.option.value]"
153
+ :title="item[props.option.text]"
154
+ clickable
155
+ @click="toggle(item, index)"
156
+ >
157
+ <template #right-icon>
158
+ <VanCheckbox ref="checkboxes" :name="item[props.option.value]" @click.stop />
159
+ </template>
160
+ </VanCell>
161
+ </VanCellGroup>
162
+ </VanCheckboxGroup>
163
+ </div>
164
+ </VanPopup>
165
+ </div>
166
+ </template>
167
+
168
+ <style lang="less" scoped>
169
+ .dh-field {
170
+ width: 100%;
171
+ padding: 0;
172
+ background:#fff;
173
+ .dh-cell.van-cell {
174
+ padding: 10px 0;
175
+ }
176
+ .dh-cell.van-cell--required::before {
177
+ left: -8px;
178
+ }
179
+ .van-popup {
180
+ border-radius: 20px 20px 0 0;
181
+ }
182
+ }
183
+ </style>
@@ -1,123 +1,122 @@
1
- <script setup lang="ts">
2
- import {
3
- Field as VanField,
4
- Picker as VanPicker,
5
- Popup as VanPopup,
6
- } from 'vant'
7
- import {computed, reactive, ref, watch, defineProps, defineEmits, defineModel, toRefs, onBeforeMount} from 'vue'
8
-
9
- const props = defineProps({
10
- columns: {
11
- type: Array,
12
- default() {
13
- return []
14
- },
15
- },
16
- option: {
17
- type: Object,
18
- default() {
19
- return { text: 'label', value: 'value', children: 'children' }
20
- },
21
- },
22
- isSearch: {
23
- type: Boolean,
24
- default: false,
25
- },
26
- offOption: { // 关闭option配置key-value;当数据是非集合的数组的时候,开启
27
- type: Boolean,
28
- default: false,
29
- },
30
- border:{ // 是否展示边框
31
- type: Boolean,
32
- default: false,
33
- },
34
- })
35
- const emits = defineEmits(['confirm', 'change', 'cancel', 'input'])
36
- const show = ref(false)
37
- const searchVal = ref('')
38
- const resultValue = defineModel()
39
- const columnsData = ref([])
40
-
41
- const resultLabel = computed({
42
- get() {
43
- const res = props.columns.filter((item) => {
44
- const data = props.offOption ? item : item[props.option.value]
45
- return data === resultValue.value
46
- })
47
- return res.length ? (props.offOption ? res[0] : res[0][props.option.text]) : ''
48
- },
49
- set() {
50
-
51
- },
52
- })
53
- function search(val) {
54
- if (val) {
55
- columnsData.value = columnsData.value.filter((item) => {
56
- const data = props.offOption ? item : item[props.option.text]
57
-
58
- return data.includes(val)
59
- })
60
- }
61
- else {
62
- columnsData.value = JSON.parse(JSON.stringify(props.columns))
63
- }
64
- }
65
- function onConfirm(value, index) {
66
- resultValue.value = props.offOption ? value.selectedValues : value.selectedValues[0]
67
- show.value = !show.value
68
- emits('confirm', value.selectedValues[0], value.selectedOptions)
69
- }
70
- function change(val, index) {
71
- emits('change', val, index, resultValue.value)
72
- }
73
- function cancel(val, index) {
74
- show.value = !show.value
75
- emits('cancel', val, index, resultValue.value)
76
- }
77
- function showPopu(disabled) {
78
- columnsData.value = JSON.parse(JSON.stringify(props.columns))
79
- // resultValue.value = `${selectValue}`
80
- if (disabled !== undefined && disabled !== false)
81
- return false
82
- else
83
- show.value = !show.value
84
- }
85
-
86
- // watch(() => selectValue, (newVal, _oldVal) => {
87
- // resultValue.value = `${newVal}`
88
- // })
89
- watch(() => resultValue, (newVal, _oldVal) => {
90
- searchVal.value = ''
91
- columnsData.value = JSON.parse(JSON.stringify(props.columns))
92
- emits('input', newVal)
93
- })
94
- </script>
95
-
96
- <template>
97
- <VanField
98
- v-model="resultLabel"
99
- v-bind="$attrs"
100
- readonly
101
- :is-link="true"
102
- :border="props.border"
103
- error-message-align="right"
104
- @click="showPopu($attrs.disabled)"
105
- />
106
- <VanPopup v-model:show="show" position="bottom">
107
- <VanField v-if="props.isSearch" v-model="searchVal" input-align="left" placeholder="搜索" @input="search" />
108
- <VanPicker
109
- v-bind="$attrs"
110
- :columns="columnsData"
111
- :columns-field-names="props.option"
112
- show-toolbar
113
- :value-key="props.option.text"
114
- @cancel="cancel"
115
- @confirm="onConfirm"
116
- @change="change"
117
- />
118
- </VanPopup>
119
- </template>
120
-
121
- <style lang="scss" scoped>
122
-
123
- </style>
1
+ <script setup lang="ts">
2
+ import {
3
+ Field as VanField,
4
+ Picker as VanPicker,
5
+ Popup as VanPopup,
6
+ } from 'vant'
7
+ import { computed, defineEmits, defineModel, defineProps, ref, watch } from 'vue'
8
+
9
+ const props = defineProps({
10
+ columns: {
11
+ type: Array,
12
+ default() {
13
+ return []
14
+ },
15
+ },
16
+ option: {
17
+ type: Object,
18
+ default() {
19
+ return { text: 'label', value: 'value', children: 'children' }
20
+ },
21
+ },
22
+ isSearch: {
23
+ type: Boolean,
24
+ default: false,
25
+ },
26
+ offOption: { // 关闭option配置key-value;当数据是非集合的数组的时候,开启
27
+ type: Boolean,
28
+ default: false,
29
+ },
30
+ border: { // 是否展示边框
31
+ type: Boolean,
32
+ default: false,
33
+ },
34
+ })
35
+ const emits = defineEmits(['confirm', 'change', 'cancel', 'input'])
36
+ const show = ref(false)
37
+ const searchVal = ref('')
38
+ const resultValue = defineModel()
39
+ const columnsData = ref([])
40
+
41
+ const resultLabel = computed({
42
+ get() {
43
+ const res = props.columns.filter((item) => {
44
+ const data = props.offOption ? item : item[props.option.value]
45
+ return data === resultValue.value
46
+ })
47
+ return res.length ? (props.offOption ? res[0] : res[0][props.option.text]) : ''
48
+ },
49
+ set() {
50
+
51
+ },
52
+ })
53
+ function search(val) {
54
+ if (val) {
55
+ columnsData.value = columnsData.value.filter((item) => {
56
+ const data = props.offOption ? item : item[props.option.text]
57
+
58
+ return data.includes(val)
59
+ })
60
+ }
61
+ else {
62
+ columnsData.value = JSON.parse(JSON.stringify(props.columns))
63
+ }
64
+ }
65
+ function onConfirm(value, _index) {
66
+ resultValue.value = props.offOption ? value.selectedValues : value.selectedValues[0]
67
+ show.value = !show.value
68
+ emits('confirm', value.selectedValues[0], value.selectedOptions)
69
+ }
70
+ function change(val, index) {
71
+ emits('change', val, index, resultValue.value)
72
+ }
73
+ function cancel(val, index) {
74
+ show.value = !show.value
75
+ emits('cancel', val, index, resultValue.value)
76
+ }
77
+ function showPopu(disabled) {
78
+ // resultValue.value = `${selectValue}`
79
+ if (disabled !== undefined && disabled !== false)
80
+ return false
81
+ columnsData.value = JSON.parse(JSON.stringify(props.columns))
82
+ show.value = !show.value
83
+ }
84
+
85
+ // watch(() => selectValue, (newVal, _oldVal) => {
86
+ // resultValue.value = `${newVal}`
87
+ // })
88
+ watch(() => resultValue, (newVal, _oldVal) => {
89
+ searchVal.value = ''
90
+ columnsData.value = JSON.parse(JSON.stringify(props.columns))
91
+ emits('input', newVal)
92
+ })
93
+ </script>
94
+
95
+ <template>
96
+ <VanField
97
+ v-model="resultLabel"
98
+ v-bind="$attrs"
99
+ readonly
100
+ :is-link="true"
101
+ :border="props.border"
102
+ error-message-align="right"
103
+ @click="showPopu($attrs.readonly)"
104
+ />
105
+ <VanPopup v-model:show="show" position="bottom">
106
+ <VanField v-if="props.isSearch" v-model="searchVal" input-align="left" placeholder="搜索" @input="search" />
107
+ <VanPicker
108
+ v-bind="$attrs"
109
+ :columns="columnsData"
110
+ :columns-field-names="props.option"
111
+ show-toolbar
112
+ :value-key="props.option.text"
113
+ @cancel="cancel"
114
+ @confirm="onConfirm"
115
+ @change="change"
116
+ />
117
+ </VanPopup>
118
+ </template>
119
+
120
+ <style lang="scss" scoped>
121
+
122
+ </style>