Skip to content

Commit c0bc148

Browse files
feat: 重构 Popover,去除第三方依赖 (#1873)
* fix: 修复 ImagePreview 在Taro编译成H5后报错的问题 * fix: 地址关闭时, Close 事件触发两次问题解决 * feat: 组件DatePicker 添加双向绑定 * docs: 组件Picker文档修改 * feat: 组件Picker与DatePicker新增属性safe-area-inset-bottom * feat: imagepreview * fix: 组件imagepreview点击视频遮罩关闭(#1729) * fix: 解决 Picker 在微信小程序中无法使用问题 (#1774) * fix: 修改 Picker 组件 v-model 失效问题 * fix: 组件NoticeBar修改height之后,垂直轮播会卡顿 * fix: 删除Datepicker Demo演示多余内容 * fix: 组件Picker在JD小程序上适配 * fix: 组件Address京东小程序适配 * feat: 京东小程序适配 * fix: 删除空格 * feat: 删除console * fix: 京东小程序imagepreview适配 * fix: 修复 imagepreview 动态设置 initNo 显示不正确问题 * fix: 组件 InfiniteLoading 某些情况下会错误触发下拉刷新#1819 * fix: 删除pullrefresh * feat: 组件 imagepreview瘦身 * feat: 组件Picker 瘦身 * feat: popover * feat: 新增 * feat: 组件 Popover 重构 * feat: 重构 popover * fix: 删除多余文件 * fix: address线上问题修改 * fix: 完善imagepreview * feat: 公共函数提取 * feat: 函数式改用 createComponent * feat: 组件冲突解决 * feat: 更换实现方式
1 parent 618dea7 commit c0bc148

File tree

8 files changed

+390
-596
lines changed

8 files changed

+390
-596
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"devDependencies": {
8484
"@commitlint/cli": "^10.0.0",
8585
"@commitlint/config-conventional": "^10.0.0",
86-
"@popperjs/core": "^2.11.5",
8786
"@tarojs/taro": "3.5.6",
8887
"@types/jest": "^26.0.22",
8988
"@types/node": "^17.0.16",

src/packages/__VUE/popover/demo.vue

+80-66
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@
44

55
<nut-row type="flex">
66
<nut-col :span="8">
7-
<nut-popover
8-
v-model:visible="visible.lightTheme"
9-
:list="iconItemList"
10-
location="bottom-start"
11-
@choose="chooseItem"
12-
>
7+
<nut-popover v-model:visible="lightTheme" :list="iconItemList" location="bottom-start" @choose="chooseItem">
138
<template #reference>
149
<nut-button type="primary" shape="square">{{ translate('light') }}</nut-button>
1510
</template>
1611
</nut-popover>
1712
</nut-col>
1813
<nut-col :span="8">
19-
<nut-popover v-model:visible="visible.darkTheme" theme="dark" :list="iconItemList">
14+
<nut-popover v-model:visible="darkTheme" theme="dark" :list="iconItemList">
2015
<template #reference>
2116
<nut-button type="primary" shape="square">{{ translate('dark') }}</nut-button>
2217
</template>
@@ -28,14 +23,14 @@
2823

2924
<nut-row type="flex">
3025
<nut-col :span="8">
31-
<nut-popover v-model:visible="visible.showIcon" theme="dark" :list="itemList">
26+
<nut-popover v-model:visible="showIcon" theme="dark" :list="itemList">
3227
<template #reference>
3328
<nut-button type="primary" shape="square">{{ translate('showIcon') }}</nut-button>
3429
</template>
3530
</nut-popover>
3631
</nut-col>
3732
<nut-col :span="8">
38-
<nut-popover v-model:visible="visible.disableAction" :list="itemListDisabled">
33+
<nut-popover v-model:visible="disableAction" :list="itemListDisabled" location="bottom-end">
3934
<template #reference>
4035
<nut-button type="primary" shape="square">{{ translate('disableAction') }}</nut-button>
4136
</template>
@@ -44,7 +39,7 @@
4439
</nut-row>
4540

4641
<h2>{{ translate('title2') }}</h2>
47-
<nut-popover v-model:visible="visible.Customized" location="bottom-start">
42+
<nut-popover v-model:visible="Customized" location="top-start" custom-class="customClass">
4843
<template #reference>
4944
<nut-button type="primary" shape="square">{{ translate('content') }}</nut-button>
5045
</template>
@@ -61,29 +56,22 @@
6156

6257
<h2>{{ translate('title3') }}</h2>
6358

64-
<nut-row type="flex" justify="center">
65-
<nut-col :span="24" style="text-align: center">
66-
<nut-popover
67-
v-model:visible="visible.customPositon"
68-
:location="curPostion"
69-
theme="dark"
70-
:list="positionList"
71-
customClass="brickBox"
72-
>
73-
<template #reference>
74-
<div class="brick"></div>
75-
</template>
76-
</nut-popover>
77-
</nut-col>
78-
</nut-row>
79-
80-
<nut-radiogroup v-model="curPostion" direction="horizontal" class="radiogroup">
81-
<nut-radio shape="button" :label="pos" v-for="(pos, i) in position" :key="i">{{ pos }}</nut-radio>
82-
</nut-radiogroup>
59+
<nut-cell title="点击查看更多方向" @click="handlePicker"></nut-cell>
60+
<nut-picker v-model:visible="showPicker" :columns="columns" title="" @change="change" :swipe-duration="500">
61+
<template #top>
62+
<div class="brickBox">
63+
<nut-popover v-model:visible="customPositon" :location="curPostion" theme="dark" :list="positionList">
64+
<template #reference>
65+
<div class="brick"></div>
66+
</template>
67+
</nut-popover>
68+
</div>
69+
</template>
70+
</nut-picker>
8371
</div>
8472
</template>
8573
<script lang="ts">
86-
import { reactive, ref } from 'vue';
74+
import { reactive, ref, toRefs } from 'vue';
8775
import { createComponent } from '@/packages/utils/create';
8876
const { createDemo, translate } = createComponent('popover');
8977
import { useTranslate } from '@/sites/assets/util/useTranslate';
@@ -116,7 +104,7 @@ const initTranslate = () =>
116104
export default createDemo({
117105
setup() {
118106
initTranslate();
119-
const visible = ref({
107+
const state = reactive({
120108
showIcon: false,
121109
placement: false,
122110
darkTheme: false,
@@ -126,22 +114,25 @@ export default createDemo({
126114
topLocation: false, //向上弹出
127115
rightLocation: false, //向右弹出
128116
leftLocation: false, //向左弹出
129-
customPositon: false
117+
customPositon: false,
118+
119+
showPicker: false
130120
});
131121
const curPostion = ref('top');
132-
const position = ref([
133-
'top',
134-
'top-start',
135-
'top-end',
136-
'right',
137-
'right-start',
138-
'right-end',
139-
'bottom',
140-
'bottom-start',
141-
'bottom-end',
142-
'left',
143-
'left-start',
144-
'left-end'
122+
123+
const columns = ref([
124+
{ text: 'top', value: 'top' },
125+
{ text: 'top-start', value: 'top-start' },
126+
{ text: 'top-end', value: 'top-end' },
127+
{ text: 'right', value: 'right' },
128+
{ text: 'right-start', value: 'right-start' },
129+
{ text: 'right-end', value: 'right-end' },
130+
{ text: 'bottom', value: 'bottom' },
131+
{ text: 'bottom-start', value: 'bottom-start' },
132+
{ text: 'bottom-end', value: 'bottom-end' },
133+
{ text: 'left', value: 'left' },
134+
{ text: 'left-start', value: 'left-start' },
135+
{ text: 'left-end', value: 'left-end' }
145136
]);
146137
147138
const iconItemList = reactive([
@@ -223,20 +214,32 @@ export default createDemo({
223214
224215
const chooseItem = (item: unknown, index: number) => {
225216
console.log(item, index);
226-
alert('selected');
227217
};
228218
219+
const handlePicker = () => {
220+
state.showPicker = true;
221+
setTimeout(() => {
222+
state.customPositon = true;
223+
});
224+
};
225+
226+
const change = ({ selectedValue }) => {
227+
curPostion.value = selectedValue[0];
228+
state.customPositon = true;
229+
};
229230
return {
230231
iconItemList,
231232
itemList,
232-
visible,
233+
...toRefs(state),
233234
itemListDisabled,
234235
selfContent,
235236
chooseItem,
236-
position,
237237
curPostion,
238238
positionList,
239-
translate
239+
translate,
240+
columns,
241+
change,
242+
handlePicker
240243
};
241244
}
242245
});
@@ -247,10 +250,12 @@ export default createDemo({
247250
}
248251
.brickBox {
249252
margin: 80px 0;
253+
display: flex;
254+
justify-content: center;
250255
.brick {
251256
width: 60px;
252257
height: 60px;
253-
background: #1989fa;
258+
background: linear-gradient(135deg, #fa2c19 0%, #fa6419 100%);
254259
border-radius: 10px;
255260
}
256261
}
@@ -271,23 +276,32 @@ export default createDemo({
271276
}
272277
}
273278
274-
.self-content {
275-
width: 195px;
276-
display: flex;
277-
flex-wrap: wrap;
278-
&-item {
279-
margin-top: 10px;
280-
margin-bottom: 10px;
281-
display: flex;
282-
justify-content: center;
283-
align-items: center;
284-
flex-direction: column;
279+
.nut-popover-content {
280+
width: 120px;
281+
}
282+
283+
.customClass {
284+
.nut-popover-content {
285+
width: auto;
285286
}
286-
&-desc {
287-
margin-top: 5px;
288-
width: 60px;
289-
font-size: 10px;
290-
text-align: center;
287+
.self-content {
288+
width: 195px;
289+
display: flex;
290+
flex-wrap: wrap;
291+
&-item {
292+
margin-top: 10px;
293+
margin-bottom: 10px;
294+
display: flex;
295+
justify-content: center;
296+
align-items: center;
297+
flex-direction: column;
298+
}
299+
&-desc {
300+
margin-top: 5px;
301+
width: 60px;
302+
font-size: 10px;
303+
text-align: center;
304+
}
291305
}
292306
}
293307
</style>

src/packages/__VUE/popover/doc.en-US.md

+8
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,14 @@ export default {
296296
| offset `v3.1.21` | the offset of the occurrence position | [number, number] | [0, 12] |
297297
| show-arrow `v3.1.21` | whether to show small arrows | boolean | true |
298298
| custom-class `v3.1.21` | custom class | string | '' |
299+
| duration `v3.1.21` | Transition duration | [number, number] | 0.3 |
300+
| iconPrefix `v3.1.21` | Icon className prefix | string | 'nut-icon'' |
301+
| overlay `v3.2.8` | Whether to show overlay | Boolean | false |
302+
| overlay-class `v3.2.8` | Custom overlay class | string | '' |
303+
| overlay-style `v3.2.8` | Custom overlay style | string | '' |
304+
| close-on-click-overlay `v3.2.8` | Whether to close when clicking overlay | boolean | true |
305+
| close-on-click-action `v3.2.8` | Whether to close when clicking action | boolean | true |
306+
| close-on-click-outside `v3.2.8` | Whether to close when clicking outside | boolean | true |
299307

300308
### List data structure
301309

src/packages/__VUE/popover/doc.md

+8
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ export default {
295295
| offset `v3.1.21` | 出现位置的偏移量 | [number, number] | [0, 12] |
296296
| show-arrow `v3.1.21` | 是否显示小箭头 | boolean | true |
297297
| custom-class `v3.1.21` | 自定义 class 值 | string | '' |
298+
| duration `v3.1.21` | 动画时长 | [number, number] | 0.3 |
299+
| iconPrefix `v3.1.21` | 图标自定义类值,等同于 Icon 组件的[ class-prefix 属性](https://nutui.jd.com/#/zh-CN/component/icon) | string | 'nut-icon'' |
300+
| overlay `v3.2.8` | 是否显示遮罩层 | Boolean | false |
301+
| overlay-class `v3.2.8` | 自定义遮罩层类名 | string | '' |
302+
| overlay-style `v3.2.8` | 自定义遮罩层样式 | string | '' |
303+
| close-on-click-overlay `v3.2.8` | 是否在点击遮罩层后关闭菜单 | boolean | true |
304+
| close-on-click-action `v3.2.8` | 是否在点击选项后关闭 | boolean | true |
305+
| close-on-click-outside `v3.2.8` | 是否在点击外部元素后关闭菜单 | boolean | true |
298306

299307
### List 数据结构
300308

0 commit comments

Comments
 (0)