@solar-taro/ui-vant 0.0.0 → 1.0.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.
Files changed (57) hide show
  1. package/cascader-picker/index.vue.d.ts +73 -0
  2. package/date-range-picker/index.vue.d.ts +75 -0
  3. package/directives/bind-function.d.ts +5 -0
  4. package/directives/datetime-picker.d.ts +5 -0
  5. package/directives/readonly.d.ts +3 -0
  6. package/index.js +1764 -0
  7. package/item/index.vue.d.ts +44 -0
  8. package/list/index.vue.d.ts +105 -0
  9. package/modal/index.vue.d.ts +56 -0
  10. package/opper-controller/index.vue.d.ts +45 -0
  11. package/overlay/overlay.d.ts +37 -0
  12. package/package.json +1 -1
  13. package/plugin.d.ts +9 -0
  14. package/select-picker/index.vue.d.ts +66 -0
  15. package/selector/index.vue.d.ts +126 -0
  16. package/tabbar/index.vue.d.ts +58 -0
  17. package/vant.interface.d.ts +91 -0
  18. package/CHANGELOG.md +0 -3
  19. package/eslint.config.cjs +0 -22
  20. package/project.json +0 -29
  21. package/src/cascader-picker/index.vue +0 -210
  22. package/src/date-range-picker/index.vue +0 -201
  23. package/src/directives/bind-function.ts +0 -22
  24. package/src/directives/datetime-picker.ts +0 -33
  25. package/src/directives/readonly.ts +0 -5
  26. package/src/item/index.vue +0 -34
  27. package/src/list/index.vue +0 -86
  28. package/src/modal/index.vue +0 -55
  29. package/src/opper-controller/index.vue +0 -365
  30. package/src/overlay/overlay.ts +0 -76
  31. package/src/plugin.ts +0 -14
  32. package/src/select-picker/index.vue +0 -80
  33. package/src/selector/index.vue +0 -252
  34. package/src/tabbar/index.vue +0 -56
  35. package/src/vant.interface.ts +0 -96
  36. package/tsconfig.json +0 -21
  37. package/tsconfig.lib.json +0 -24
  38. package/tsconfig.spec.json +0 -28
  39. package/vite.config.ts +0 -130
  40. /package/{src/cascader-picker/index.ts → cascader-picker/index.d.ts} +0 -0
  41. /package/{src/date-range-picker/index.ts → date-range-picker/index.d.ts} +0 -0
  42. /package/{src/date-range-picker → date-range-picker}/index.scss +0 -0
  43. /package/{src/directives/index.ts → directives/index.d.ts} +0 -0
  44. /package/{src/index.ts → index.d.ts} +0 -0
  45. /package/{src/index.scss → index.scss} +0 -0
  46. /package/{src/item/index.ts → item/index.d.ts} +0 -0
  47. /package/{src/item → item}/index.scss +0 -0
  48. /package/{src/list/index.ts → list/index.d.ts} +0 -0
  49. /package/{src/modal/index.ts → modal/index.d.ts} +0 -0
  50. /package/{src/opper-controller/index.ts → opper-controller/index.d.ts} +0 -0
  51. /package/{src/opper-controller → opper-controller}/index.scss +0 -0
  52. /package/{src/overlay/index.ts → overlay/index.d.ts} +0 -0
  53. /package/{src/select-picker/index.ts → select-picker/index.d.ts} +0 -0
  54. /package/{src/selector/index.ts → selector/index.d.ts} +0 -0
  55. /package/{src/selector → selector}/index.scss +0 -0
  56. /package/{src/tabbar/index.ts → tabbar/index.d.ts} +0 -0
  57. /package/{src/tabbar → tabbar}/index.scss +0 -0
package/project.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "name": "ui-vant",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "packages/ui-vant/src",
5
- "projectType": "library",
6
- "tags": [],
7
- "// targets": "to see all targets run: nx show project ui-vant --web",
8
- "targets": {
9
- "postbuild": {
10
- "executor": "nx:run-commands",
11
- "dependsOn": [
12
- "build"
13
- ],
14
- "options": {
15
- "commands": [
16
- "node scripts/copy-assets.js ui-vant **/*.scss"
17
- ]
18
- }
19
- },
20
- "release:dev": {
21
- "executor": "nx:run-commands",
22
- "options": {
23
- "commands": [
24
- "yalc publish dist/ui-vant"
25
- ]
26
- }
27
- }
28
- }
29
- }
@@ -1,210 +0,0 @@
1
- <template>
2
- <van-popup :show="show" position="bottom" :round="true" :close-on-click-overlay="true" @close="close()">
3
- <van-picker
4
- v-bind="$attrs"
5
- :title="title"
6
- :show-toolbar="true"
7
- :value-key="labelKey"
8
- :columns="columns"
9
- :loading="loading"
10
- @cancel="cancel()"
11
- @confirm="onConfirm($event)"
12
- @change="onChange($event)" />
13
- <van-search
14
- v-if="searchable && options.length"
15
- shape="round"
16
- input-align="center"
17
- placeholder="请输入搜索关键词"
18
- @change="onKeywordChange($event)" />
19
- </van-popup>
20
- </template>
21
-
22
- <script lang="ts" setup>
23
- import { cloneDeep } from 'lodash-es';
24
- import { computed, ref } from 'vue';
25
- import { VanPickerColumn } from '../vant.interface';
26
-
27
- interface Node {
28
- children?: Node[];
29
- [key: string]: any;
30
- }
31
-
32
- defineOptions({
33
- inheritAttrs: false
34
- })
35
-
36
- const emit = defineEmits<{
37
- close: [],
38
- cancel: [any],
39
- confirm: [any],
40
- 'update:show': [boolean],
41
- 'update:modelValue': [any]
42
- }>()
43
-
44
- const props = withDefaults(
45
- defineProps<{
46
- show: boolean,
47
- labelKey?: string,
48
- valueKey?: string,
49
- pidKey?: string,
50
- searchable?: boolean,
51
- title: string,
52
- loading?: boolean
53
- /** [[level1 list], [level2 list], [level3 list]] */
54
- options: any[][],
55
- modelValue: string | number | undefined,
56
- required?: boolean
57
- }>(),
58
- {
59
- labelKey: 'fullName',
60
- valueKey: 'id',
61
- pidKey: 'pid',
62
- searchable: true,
63
- options: () => []
64
- }
65
- )
66
-
67
- const keyword = ref('');
68
-
69
- const trees = computed(() => {
70
- const optionsList: Node[][] = cloneDeep(props.options);
71
-
72
- // 给每个 node 加上 children
73
- // 注意,这里跳过最后一个,因为最后一个肯定都是 child,不需要添加 children
74
- for (let index = 0; index < optionsList.length - 1; index++) {
75
- const options = optionsList[index];
76
-
77
- for (let idx = 0; idx < options.length; idx++) {
78
- const option = options[idx];
79
- option.children = optionsList[index + 1].filter(child => child[props.pidKey] === option[props.valueKey]);
80
- }
81
- }
82
-
83
- return optionsList[0];
84
- });
85
- /** 节点打平的列表 */
86
- const list = computed(() => cloneDeep(trees.value).map(option => flatTree(option)).flat())
87
- const columns = computed(() => {
88
- // 找到选中的值
89
- const model = props.options[props.options.length - 1].find(o => o[props.valueKey] === props.modelValue);
90
- return model ? initColumnsByDefaultValue(model) : initColumns();
91
- })
92
-
93
- function cancel() {
94
- props.required || emit('update:modelValue', null);
95
- emit('cancel', props.modelValue);
96
- close();
97
- }
98
- function close() {
99
- emit('update:show', false);
100
- emit('close');
101
- }
102
- function onConfirm({ detail }: any) {
103
- // 拿到最后一个
104
- const value = detail.value[detail.value.length - 1];
105
-
106
- emit('update:modelValue', value[props.valueKey]);
107
- emit('confirm', findParents(value));
108
- emit('update:show', false);
109
- }
110
- function onChange({ detail }: any) {
111
- const { picker, value, index } = detail;
112
-
113
- // 没有关键字且不是在滚动最后一行
114
- if (!keyword.value && index < props.options.length - 1) {
115
- picker.setColumnValues(
116
- index + 1,
117
- props.options[index + 1].filter(o => o[props.pidKey] === value[index][props.valueKey])
118
- );
119
- }
120
- }
121
- function onKeywordChange({ detail }: any) {
122
- keyword.value = detail.trim().toLowerCase();
123
- initColumns();
124
- }
125
- /**
126
- * 找到当前值的所有 parent
127
- * @param child
128
- * @returns [parent1, parent2, ..., child]
129
- */
130
- function findParents(child: Record<string, unknown>) {
131
- const result = [props.options[props.options.length - 1].find(o => o[props.valueKey] === child[props.valueKey] && o[props.pidKey] === child[props.pidKey])];
132
- for (let index = props.options.length - 2; index >= 0; index--) {
133
- result.unshift(
134
- props.options[index].find(o => o[props.valueKey] === result[0]?.[props.pidKey])
135
- );
136
- }
137
-
138
- return result;
139
- }
140
- /**
141
- * 把 tree 打平成 list
142
- * ```
143
- * ↗ b
144
- * a -> [a/b, a/c]
145
- * ↘ c
146
- * ```
147
- * @param node
148
- * @param perfix
149
- */
150
- function flatTree(node: Node, perfix: string = '') {
151
- let result = [] as Node[];
152
- let name = perfix + node[props.labelKey];
153
-
154
- if (node.children?.length) {
155
- node.children.forEach(child => {
156
- result = result.concat(flatTree(child, name + ' / '))
157
- })
158
- } else {
159
- node[props.labelKey] = name;
160
- result.push(node);
161
- }
162
-
163
- return result;
164
- }
165
- function initColumns(): VanPickerColumn<Node>[] {
166
- if (keyword.value) {
167
- return [{
168
- values: list.value.filter(o => o[props.labelKey].toLowerCase().includes(keyword.value))
169
- }];
170
- }
171
-
172
- const columns = [];
173
-
174
- let nodes: Node[] | undefined = trees.value;
175
-
176
- while (nodes) {
177
- columns.push({ values: nodes });
178
- // 替换成当前值的第一个的元素的 children
179
- nodes = nodes[0]?.children;
180
- }
181
-
182
- return columns;
183
- }
184
- function initColumnsByDefaultValue(value: Record<string, unknown>): VanPickerColumn<Node>[] {
185
- if (keyword.value) {
186
- const values = list.value.filter(o => o[props.labelKey].toLowerCase().includes(keyword.value));
187
- return [{
188
- values,
189
- defaultIndex: values.findIndex(o => o[props.valueKey] === value[props.valueKey])
190
- }];
191
- }
192
-
193
- const columns = [];
194
-
195
- // 倒序去找 parent
196
- for (let index = props.options.length - 1; index >= 0; index--) {
197
- const values = props.options[index].filter(o => o[props.pidKey] === value[props.pidKey]);
198
- columns[index] = {
199
- values,
200
- defaultIndex: values.findIndex(o => o[props.valueKey] === value[props.valueKey])
201
- }
202
- // 找当前值的上一级
203
- if (index > 0) {
204
- value = props.options[index - 1].find(o => o[props.valueKey] === value[props.pidKey])!;
205
- }
206
- }
207
-
208
- return columns
209
- }
210
- </script>
@@ -1,201 +0,0 @@
1
- <template>
2
- <slot :present="present">
3
- <van-field
4
- v-readonly
5
- v-bind="$attrs"
6
- :label="label"
7
- :value="inputValue"
8
- :placeholder="internalPlaceholder.join(separator)"
9
- @click-input="present()">
10
- <slot-view name="right-icon">
11
- <van-icon v-if="canClear" name="clear" @tap="clear()" />
12
- </slot-view>
13
- </van-field>
14
- </slot>
15
-
16
- <van-action-sheet
17
- :show="show"
18
- :title="internalTitle"
19
- :close-on-click-overlay="true"
20
- @close="close()"
21
- @cancel="close()">
22
- <view class="sun-date-range-picker-input-group">
23
- <view
24
- class="sun-date-range-picker-input"
25
- :class="{ 'sun-date-range-picker-input-active': activeIndex === 0 }"
26
- @tap="activate(0)">
27
- <view v-if="internalModelValue[0]" class="sun-date-range-picker-input-value">
28
- {{ date(internalModelValue[0], internalFormat) }}
29
- </view>
30
- <view v-else class="sun-date-range-picker-input-placeholder">请选择</view>
31
- <view class="sun-date-range-picker-input-label">{{ internalPlaceholder[0] }}</view>
32
- </view>
33
- <van-icon v-if="true" name="down" color="var(--color-gray)" />
34
- <view
35
- class="sun-date-range-picker-input"
36
- :class="{ 'sun-date-range-picker-input-active': activeIndex === 1 }"
37
- @tap="activate(1)">
38
- <view v-if="internalModelValue[1]" class="date-range-picker-input-value">
39
- {{ date(internalModelValue[1], internalFormat) }}
40
- </view>
41
- <view v-else class="sun-date-range-picker-input-placeholder">请选择</view>
42
- <view class="sun-date-range-picker-input-label">{{ internalPlaceholder[1] }}</view>
43
- </view>
44
- </view>
45
- <van-datetime-picker
46
- v-datetime-picker
47
- :id="id"
48
- :type="type"
49
- :show-toolbar="false"
50
- :value="currentDate"
51
- :min-date="minDate"
52
- :max-date="maxDate"
53
- @modify="onValueChange($event.detail)" />
54
-
55
- <view class="sun-date-range-picker-btn-wrapper">
56
- <van-button type="primary" round="true" block="true" @tap="submit()">
57
- {{ internalModelValue[0] && internalModelValue[1] ? '确定' : '继续' }}
58
- </van-button>
59
- </view>
60
- </van-action-sheet>
61
- </template>
62
-
63
- <script lang="ts">
64
- let nextId = 1;
65
- </script>
66
-
67
- <script lang="ts" setup>
68
- import { date } from '@solar-taro/core';
69
- import { computed, ref } from 'vue';
70
- import { vDatetimePicker } from '../directives';
71
-
72
- const props = withDefaults(
73
- defineProps<{
74
- id?: string;
75
- type?: 'date' | 'datetime',
76
- label?: string;
77
- title?: string;
78
- placeholder?: [string, string];
79
- modelValue: [number?, number?];
80
- required?: boolean;
81
- format?: string;
82
- minDate?: number;
83
- maxDate?: number;
84
- }>(),
85
- {
86
- id: () => `van-datetime-picker-${nextId++}`,
87
- type: 'date',
88
- minDate: () => new Date(new Date().getFullYear() - 5, 0, 0, 0, 0, 0).getTime(),
89
- maxDate: () => new Date(new Date().getFullYear() + 5, 0, 0, 0, 0, 0).getTime(),
90
- }
91
- );
92
-
93
- const emit = defineEmits<{
94
- (e: 'update:modelValue', v: [number?, number?]): void;
95
- (e: 'confirm', v: [number, number]): void;
96
- (e: 'clear', v: [number?, number?]): void;
97
- (e: 'close'): void;
98
- }>();
99
-
100
- const separator = ' ~ ';
101
-
102
- // 内部的模型值,用户操作确定后才同步出去
103
- const internalModelValue = ref<[number?, number?]>([...props.modelValue]);
104
- const currentDate = ref(props.modelValue[0] ?? defaultDate());
105
- const show = ref(true);
106
- const activeIndex = ref<0 | 1>(0);
107
-
108
- const inputValue = computed(() => {
109
- const [start, end] = props.modelValue;
110
-
111
- if (start && end) {
112
- return date(start, internalFormat.value) + separator + date(end, internalFormat.value);
113
- }
114
-
115
- return '';
116
- });
117
- const canClear = computed(() => props.modelValue.length && !props.required);
118
- // eslint-disable-next-line vue/return-in-computed-property
119
- const internalFormat = computed(() => {
120
- if (props.format) {
121
- return props.format;
122
- }
123
-
124
- switch (props.type) {
125
- case 'date': return 'yyyy-MM-dd';
126
- case 'datetime': return 'yyyy-MM-dd HH:mm';
127
- }
128
- });
129
- // eslint-disable-next-line vue/return-in-computed-property
130
- const internalTitle = computed(() => {
131
- if (props.title) {
132
- return props.title;
133
- }
134
-
135
- switch (props.type) {
136
- case 'date': return '请选择日期';
137
- case 'datetime': return '请选择时间';
138
- }
139
- });
140
- // eslint-disable-next-line vue/return-in-computed-property
141
- const internalPlaceholder = computed(() => {
142
- if (props.placeholder) {
143
- return props.placeholder;
144
- }
145
-
146
- switch (props.type) {
147
- case 'date': return ['开始日期', '结束日期'];
148
- case 'datetime': return ['开始时间', '结束时间'];
149
- }
150
- });
151
-
152
- function defaultDate() {
153
- const today = new Date();
154
- const currentMin = today.getMinutes();
155
-
156
- switch (props.type) {
157
- case 'date':
158
- return today.setHours(0, 0, 0, 0);
159
-
160
- case 'datetime':
161
- return today.setMinutes(currentMin - currentMin % 5); // 处理不能被5整除的数
162
- }
163
- }
164
-
165
- function present() {
166
- show.value = true;
167
- activate(0);
168
- }
169
-
170
- function close() {
171
- show.value = false;
172
- emit('close');
173
- }
174
-
175
- function clear() {
176
- internalModelValue.value = [];
177
- emit('clear', props.modelValue);
178
- emit('update:modelValue', []);
179
- }
180
-
181
- function activate(index: 0 | 1) {
182
- activeIndex.value = index;
183
- currentDate.value = internalModelValue.value[index] ||= defaultDate();
184
- }
185
-
186
- function onValueChange(value: number) {
187
- internalModelValue.value[activeIndex.value] = value;
188
- }
189
-
190
- function submit() {
191
- const [start, end] = internalModelValue.value;
192
- // 检查有没有值还没填
193
- if (!start || !end) {
194
- return activate(start ? 1 : 0);
195
- }
196
-
197
- emit('update:modelValue', [...internalModelValue.value]);
198
- emit('confirm', internalModelValue.value as [number, number]);
199
- close();
200
- }
201
- </script>
@@ -1,22 +0,0 @@
1
- import { getCurrentInstance, nextTick, PageInstance } from '@tarojs/taro';
2
- import { Directive } from 'vue';
3
-
4
- function setComponentData(page: PageInstance, id: string, prop: string, value: unknown) {
5
- const cmp = page.selectComponent!('#' + id);
6
- cmp.setData!({ [prop]: value });
7
- }
8
-
9
- export const vBindFn: Directive<{ id: string }, (...args: any[]) => any> = {
10
- mounted(element, binding) {
11
- const { page } = getCurrentInstance();
12
- nextTick(() => {
13
- nextTick(() => {
14
- setComponentData(page!, element.id, binding.arg!, binding.value);
15
- });
16
- });
17
- },
18
- updated(element, binding) {
19
- const { page } = getCurrentInstance();
20
- setComponentData(page!, element.id, binding.arg!, binding.value);
21
- }
22
- }
@@ -1,33 +0,0 @@
1
- import { getCurrentInstance, nextTick } from '@tarojs/taro';
2
- import { Directive } from 'vue';
3
-
4
- export const vDatetimePicker: Directive<{ id: string }> = {
5
- mounted(element) {
6
- const { page } = getCurrentInstance();
7
- nextTick(() => {
8
- nextTick(() => {
9
- const cmp = page!.selectComponent!(`#${element.id}`);
10
-
11
- cmp.setData!({
12
- formatter: (type: 'year' | 'month' | 'day' | 'hour' | 'minute', value: string) => {
13
- switch (type) {
14
- case 'year': return `${value}年`;
15
- case 'month': return `${value}月`;
16
- case 'day': return `${value}日`;
17
- case 'hour': return `${value}时`;
18
- case 'minute': return `${value}分`;
19
- }
20
- },
21
- filter: (type: 'year' | 'month' | 'day' | 'hour' | 'minute', values: string[]) => {
22
- if (type === 'minute') {
23
- return values.filter(option => +option % 5 === 0);
24
- }
25
- return values;
26
- }
27
- });
28
- // @ts-expect-error van-datetime-picker
29
- cmp.updateValue();
30
- });
31
- })
32
- }
33
- }
@@ -1,5 +0,0 @@
1
- import { Directive } from 'vue';
2
-
3
- export const vReadonly: Directive<any, boolean | undefined> = (element, binding) => {
4
- element.setAttribute('readonly', binding.value ?? true);
5
- }
@@ -1,34 +0,0 @@
1
- <template>
2
- <view class="sun-item" hover-class="hover" :class="classes">
3
- <slot name="start"></slot>
4
- <view class="sun-item-inner">
5
- <view class="sun-item-content-wrapper">
6
- <slot></slot>
7
- </view>
8
- <slot name="end"></slot>
9
- <van-icon v-if="detail" class="sun-item-detail-icon" name="arrow" color="var(--arrow-color)" />
10
- </view>
11
- </view>
12
- </template>
13
-
14
- <script lang="ts" setup>
15
- import { computed } from 'vue';
16
-
17
- const props = withDefaults(
18
- defineProps<{
19
- detail?: boolean;
20
- lines?: boolean;
21
- clickable?: boolean;
22
- }>(),
23
- {
24
- lines: true
25
- }
26
- );
27
-
28
- const classes = computed(() => {
29
- return {
30
- 'sun-item-lines-none': !props.lines,
31
- 'sun-item-clickable': props.detail || props.clickable
32
- };
33
- });
34
- </script>
@@ -1,86 +0,0 @@
1
- <template>
2
- <scroll-view
3
- v-bind="$attrs"
4
- class="sun-list"
5
- :enhanced="true"
6
- :scroll-y="true"
7
- :lower-threshold="300"
8
- :enable-flex="flex"
9
- :refresher-enabled="refresher"
10
- :refresher-triggered="refreshing"
11
- :refresher-background="refresherBg"
12
- @refresherrefresh="vibrator.short('light'); emit('refresh')"
13
- @scrolltolower="emit('lower')">
14
- <slot></slot>
15
- <view
16
- v-show="!data.length"
17
- class="sun-list-placeholder"
18
- style="display:flex;justify-content:center;align-items:center;height:85%;">
19
- <sun-spinner v-if="loading" :spinning="true">{{ loadingText }}</sun-spinner>
20
- <slot v-else name="empty">
21
- <van-empty :image="emptyType" :description="emptyText">
22
- <slot name="empty-content"></slot>
23
- </van-empty>
24
- </slot>
25
- </view>
26
-
27
- <view
28
- v-show="data.length && loading && !refreshing"
29
- class="sun-list-loading-wrapper"
30
- style="text-align:center;padding: 10rpx;">
31
- <sun-spinner :spinning="true" size="small" />
32
- </view>
33
- <!-- 修复最后一个元素 margin 失效问题:https://developers.weixin.qq.com/community/develop/doc/0004c6b01a0670af2b1e50ef856c00?_at=1695569138914 -->
34
- <view style="position:absolute;height:1px;width:1px;overflow:hidden;"></view>
35
- </scroll-view>
36
- </template>
37
-
38
- <script lang="ts" setup>
39
- import { vibrator } from '@solar-taro/core';
40
- import { SunSpinner } from '@solar-taro/ui-sun';
41
- import { PropType } from 'vue';
42
-
43
- const emit = defineEmits<{
44
- (e: 'refresh'): void;
45
- (e: 'lower'): void;
46
- }>();
47
-
48
- defineProps({
49
- refreshing: {
50
- type: Boolean,
51
- default: false
52
- },
53
- flex: {
54
- type: Boolean,
55
- default: false
56
- },
57
- loading: {
58
- type: Boolean,
59
- default: false
60
- },
61
- loadingText: {
62
- type: String,
63
- default: 'Loading'
64
- },
65
- data: {
66
- type: Array,
67
- default: []
68
- },
69
- refresher: {
70
- type: Boolean,
71
- default: true
72
- },
73
- refresherBg: {
74
- type: String,
75
- default: 'transparent'
76
- },
77
- emptyType: {
78
- type: String as PropType<'error' | 'network' | 'search' | 'default'>,
79
- default: 'default'
80
- },
81
- emptyText: {
82
- type: String,
83
- default: '暂无数据'
84
- }
85
- });
86
- </script>
@@ -1,55 +0,0 @@
1
- <template>
2
- <van-action-sheet
3
- :show="show"
4
- :title="title"
5
- :close-on-click-overlay="closable"
6
- @close="emit('update:show', false)">
7
- <slot></slot>
8
-
9
- <view v-if="showButtons" class="van-button-container van-button-group">
10
- <slot name="buttons">
11
- <van-button type="primary" round="true" block="true" :disabled="confirmDisabled" @click="emit('confirm')">
12
- {{ confirmText }}
13
- </van-button>
14
- </slot>
15
- </view>
16
- </van-action-sheet>
17
- </template>
18
-
19
- <script lang="ts" setup>
20
- import { offKeyboardHeightChange, onKeyboardHeightChange } from '@tarojs/taro';
21
- import { computed, onUnmounted, ref } from 'vue';
22
-
23
- const emit = defineEmits<{
24
- 'update:show': [boolean]
25
- 'confirm': []
26
- }>();
27
-
28
- withDefaults(
29
- defineProps<{
30
- show: boolean
31
- title: string
32
- showButtons?: boolean
33
- confirmText?: string
34
- confirmDisabled?: boolean
35
- }>(),
36
- {
37
- confirmText: '确认',
38
- showButtons: true
39
- }
40
- );
41
-
42
- const keyboardHeight = ref(0);
43
- // 键盘打开时,点击浮层禁止关闭
44
- const closable = computed(() => keyboardHeight.value === 0);
45
-
46
- function cb(value: { height: number }) {
47
- keyboardHeight.value = value.height;
48
- }
49
-
50
- onKeyboardHeightChange(cb);
51
-
52
- onUnmounted(() => {
53
- offKeyboardHeightChange(cb);
54
- });
55
- </script>