Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 重构 Popover,去除第三方依赖 #1873

Merged
merged 58 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6c6de67
fix: 修复 ImagePreview 在Taro编译成H5后报错的问题
yangxiaolu1993 Sep 22, 2022
8dd3a46
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Sep 22, 2022
9c51a98
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Sep 22, 2022
06bd06e
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Sep 23, 2022
d3cb370
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 12, 2022
c040c5c
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 13, 2022
cce2619
fix: 地址关闭时, Close 事件触发两次问题解决
yangxiaolu1993 Oct 13, 2022
c4d76a5
feat: 组件DatePicker 添加双向绑定
yangxiaolu1993 Oct 13, 2022
4382636
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 13, 2022
54e281a
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 21, 2022
9797b0c
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 21, 2022
fc382b1
docs: 组件Picker文档修改
yangxiaolu1993 Oct 21, 2022
c003337
feat: 组件Picker与DatePicker新增属性safe-area-inset-bottom
yangxiaolu1993 Oct 21, 2022
17feea3
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 21, 2022
70024fd
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 24, 2022
437e345
feat: imagepreview
yangxiaolu1993 Oct 24, 2022
4d5fcf0
fix: 组件imagepreview点击视频遮罩关闭(#1729)
yangxiaolu1993 Oct 25, 2022
30ec6af
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 25, 2022
6df0424
fix: 解决 Picker 在微信小程序中无法使用问题 (#1774)
yangxiaolu1993 Oct 26, 2022
206d975
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 26, 2022
72eca76
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 26, 2022
221bfd4
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Oct 28, 2022
e3e8d5b
fix: 修改 Picker 组件 v-model 失效问题
yangxiaolu1993 Oct 28, 2022
6134fb1
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Nov 2, 2022
aa79cb0
fix: 组件NoticeBar修改height之后,垂直轮播会卡顿
yangxiaolu1993 Nov 2, 2022
ca4fe23
fix: 删除Datepicker Demo演示多余内容
yangxiaolu1993 Nov 2, 2022
9d2bf97
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Nov 2, 2022
d373aac
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Nov 11, 2022
ba3bb84
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Nov 14, 2022
bc8c643
fix: 组件Picker在JD小程序上适配
yangxiaolu1993 Nov 14, 2022
05f1645
fix: 组件Address京东小程序适配
yangxiaolu1993 Nov 14, 2022
8b1c72b
feat: 京东小程序适配
yangxiaolu1993 Nov 15, 2022
4d3597d
fix: 删除空格
yangxiaolu1993 Nov 15, 2022
88b804a
feat: 删除console
yangxiaolu1993 Nov 15, 2022
99027ca
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Nov 16, 2022
6b7a71b
fix: 京东小程序imagepreview适配
yangxiaolu1993 Nov 16, 2022
81c00d8
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Nov 18, 2022
9c3feca
fix: 修复 imagepreview 动态设置 initNo 显示不正确问题
yangxiaolu1993 Nov 18, 2022
07617b7
fix: 组件 InfiniteLoading 某些情况下会错误触发下拉刷新#1819
yangxiaolu1993 Nov 18, 2022
2aea484
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Nov 21, 2022
40599db
fix: 删除pullrefresh
yangxiaolu1993 Nov 21, 2022
cecdc6e
feat: 组件 imagepreview瘦身
yangxiaolu1993 Nov 22, 2022
ff7741b
feat: 组件Picker 瘦身
yangxiaolu1993 Nov 22, 2022
c7fd37a
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Nov 22, 2022
f18d320
feat: popover
yangxiaolu1993 Nov 23, 2022
db057c4
feat: 新增
yangxiaolu1993 Nov 24, 2022
a756f05
feat: 组件 Popover 重构
yangxiaolu1993 Nov 24, 2022
7723e7f
feat: 重构 popover
yangxiaolu1993 Nov 24, 2022
28ea60d
fix: 删除多余文件
yangxiaolu1993 Nov 24, 2022
e65f493
fix: address线上问题修改
yangxiaolu1993 Nov 25, 2022
5f3b1c5
fix: 完善imagepreview
yangxiaolu1993 Nov 28, 2022
e6bcfc7
feat: 代码冲突合并 Popop 与 imagepreview
yangxiaolu1993 Nov 28, 2022
d816bca
feat: 公共函数提取
yangxiaolu1993 Nov 28, 2022
4058a1a
Merge branch 'jdf2e:next' into next
yangxiaolu1993 Nov 28, 2022
9ffe83d
feat: 函数式改用 createComponent
yangxiaolu1993 Nov 28, 2022
8d8fc84
fix: 冲突解决
yangxiaolu1993 Nov 28, 2022
18e2797
feat: 组件冲突解决
yangxiaolu1993 Nov 28, 2022
0e30d50
feat: 更换实现方式
yangxiaolu1993 Nov 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"devDependencies": {
"@commitlint/cli": "^10.0.0",
"@commitlint/config-conventional": "^10.0.0",
"@popperjs/core": "^2.11.5",
"@tarojs/taro": "3.5.6",
"@types/jest": "^26.0.22",
"@types/node": "^17.0.16",
Expand Down
10 changes: 0 additions & 10 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,6 @@
"show": true,
"author": "wangyue217"
},
{
"version": "3.0.0",
"name": "PullRefresh",
"type": "component",
"cName": "下拉刷新",
"desc": "下拉刷新",
"sort": 16,
"show": false,
"author": "yangxiaolu3"
},
{
"version": "3.0.0",
"name": "Switch",
Expand Down
20 changes: 11 additions & 9 deletions src/packages/__VUE/address/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@
:class="[selectedRegion[tabName[tabIndex]].id == item.id ? 'active' : '']"
@click="nextAreaList(item)"
>
<nut-icon
class="region-item-icon"
type="self"
v-bind="$attrs"
:name="selectedIcon"
size="13px"
v-if="selectedRegion[tabName[tabIndex]].id == item.id"
></nut-icon
>{{ item.name }}
<div>
<nut-icon
class="region-item-icon"
type="self"
v-bind="$attrs"
:name="selectedIcon"
size="13px"
v-if="selectedRegion[tabName[tabIndex]].id == item.id"
></nut-icon
>{{ item.name }}
</div>
</li>
</ul>
</view>
Expand Down
67 changes: 25 additions & 42 deletions src/packages/__VUE/dialog/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Dialog from './index.vue';
import { render, createVNode, h, VNode, CSSProperties } from 'vue';
import { h, VNode, CSSProperties } from 'vue';
import Popup from '../popup/index.vue';
import Icon from '../icon/index.vue';
import Button from '../button/index.vue';
import OverLay from '../overlay/index.vue';
import { CreateComponent } from '@/packages/utils/create';
export class DialogOptions {
title?: string = '';
content?: string | VNode = '';
Expand Down Expand Up @@ -37,51 +42,29 @@ class DialogFunction {
instance: any;
constructor(_options: DialogOptions) {
let options = Object.assign(this.options, _options);
let elWarp: HTMLElement = document.body;
let teleport = options.teleport as string;
if (teleport != 'body') {
if (typeof teleport == 'string') {
elWarp = document.querySelector(teleport) as HTMLElement;
} else {
elWarp = options.teleport as HTMLElement;
}
}
const root = document.createElement('view');
root.id = 'dialog-' + options.id;
const Wrapper = {
setup() {
options.onUpdate = (val: boolean) => {
if (val == false) {
elWarp.removeChild(root);
const { unmount } = CreateComponent(options, {
name: 'dialog',
components: [Popup, Icon, Button, OverLay],
wrapper: (elWarp: any, root: any) => {
return {
setup() {
options.onUpdate = (val: boolean) => {
if (val == false) {
unmount();
}
};
if (options?.onOpened) {
options?.onOpened();
}
options.teleport = `#${root.id}`;
return () => {
return h(Dialog, options);
};
}
};
if (options?.onOpened) {
options?.onOpened();
}
options.teleport = `#${root.id}`;
return () => {
return h(Dialog, options);
};
}
};
this.instance = createVNode(Wrapper);
elWarp.appendChild(root);
render(this.instance, root);
});
}

close = () => {
// if (this.instance) {
// this.instance.component.ctx.close();
// }
};

setDefaultOptions = (options: DialogOptions) => {
// Object.assign(this.currentOptions, options);
};

resetDefaultOptions = () => {
// Dialog.currentOptions = { ...Dialog.defaultOptions };
};
}

const _Dialog = function (options: DialogOptions) {
Expand Down
34 changes: 10 additions & 24 deletions src/packages/__VUE/dialog/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@
import { onMounted, computed, watch, ref, PropType, VNode, CSSProperties } from 'vue';
import { createComponent } from '@/packages/utils/create';
const { componentName, create, translate } = createComponent('dialog');
import Popup from '../popup/index.vue';
import { funInterceptor, Interceptor } from '@/packages/utils/util';
import { popupProps } from '../popup/props';
import Button from '../button/index.vue';

import { isPromise } from '@/packages/utils/util';
export default create({
inheritAttrs: false,
components: {
[Popup.name]: Popup,
[Button.name]: Button
},
components: {},
props: {
...popupProps,
closeOnClickOverlay: {
Expand Down Expand Up @@ -114,9 +111,7 @@ export default create({
popStyle: {
type: Object as PropType<CSSProperties>
},
beforeClose: {
type: Function
}
beforeClose: Function as PropType<Interceptor>
},
emits: ['update', 'update:visible', 'ok', 'cancel', 'opened', 'closed'],
setup(props, { emit }) {
Expand Down Expand Up @@ -152,22 +147,13 @@ export default create({
};

const closed = (action: string) => {
if (props.beforeClose) {
const result = props.beforeClose(action);
if (isPromise(result)) {
result.then((bool) => {
if (bool) {
update(false);
emit('closed');
} else {
// 用户阻止删除
}
});
funInterceptor(props.beforeClose, {
args: [action],
done: () => {
update(false);
emit('closed');
}
} else {
update(false);
emit('closed');
}
});
};

const onCancel = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/packages/__VUE/imagepreview/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ export default createDemo({
ImagePreview({
show: true,
images: resData.imgData,
onClose
onClose: () => onClose()
});
};

const hideFn = (i: number) => {
(resData as any)['showPreview' + i] = false;
console.log('guansebi');
};

return {
Expand Down
96 changes: 23 additions & 73 deletions src/packages/__VUE/imagepreview/imagePreviewItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,28 @@
<view
:style="imageStyle"
class="nut-imagepreview-box"
v-if="image && image.src"
@touchstart="onTouchStart"
@touchmove="onTouchMove"
@touchend="onTouchEnd"
@touchcancel="onTouchEnd"
>
<img :src="image.src" class="nut-imagepreview-img" @load="imageLoad" />
</view>

<view
class="nut-imagepreview-box"
v-if="video && video.source"
@click="videoClick"
@touchstart="onTouchStart"
@touchmove="onTouchMove"
@touchend="onTouchEnd"
@touchcancel="onTouchEnd"
>
<nut-video :source="video.source" :options="video.options"></nut-video>
<img v-if="image && image.src" :src="image.src" class="nut-imagepreview-img" @load="imageLoad" />
<nut-video v-if="video && video.source" :source="video.source" :options="video.options"></nut-video>
</view>
</nut-swiper-item>
</template>
<script lang="ts">
import { toRefs, reactive, watch, computed, CSSProperties, PropType } from 'vue';
import { createComponent } from '@/packages/utils/create';
import Popup from '../popup/index.vue';
import Video from '../video/index.vue';
import Swiper from '../swiper/index.vue';
import SwiperItem from '../swiperitem/index.vue';
import Icon from '../icon/index.vue';
import { useTouch } from '@/packages/utils/useTouch';
import { preventDefault } from '@/packages/utils/util';
import { ImageInterface } from './types';
import { baseProps } from './types';
const { create } = createComponent('imagepreviewitem');

export default create({
props: {
show: {
type: Boolean,
default: false
},
initNo: Number,
...baseProps,
image: {
type: Object as PropType<ImageInterface>,
default: () => ({})
Expand All @@ -52,36 +33,17 @@ export default create({
type: Object,
default: () => ({})
},

showIndex: {
type: Boolean,
default: true
},
rootWidth: {
type: Number,
default: 0
},
rootHeight: {
type: Number,
default: 0
},
minZoom: {
type: Number,
default: 1 / 3
},
maxZoom: {
type: Number,
default: 3
}
},
emits: ['close', 'scale'],
components: {
[Popup.name]: Popup,
[Video.name]: Video,
[Swiper.name]: Swiper,
[SwiperItem.name]: SwiperItem,
[Icon.name]: Icon
},
components: {},

setup(props, { emit }) {
const state = reactive({
Expand All @@ -103,20 +65,25 @@ export default create({
return state.imageRatio > rootRatio;
});

// 图片放大
// 图片缩放
const imageStyle = computed(() => {
const { scale, moveX, moveY, moving, zooming } = state;
const style: CSSProperties = {
transitionDuration: zooming || moving ? '0s' : '.3s'
};

if (scale !== 1) {
const offsetX = moveX / scale;
const offsetY = moveY / scale;
style.transform = `scale(${scale}, ${scale}) translate(${offsetX}px, ${offsetY}px)`;
const images = props.image;
if (images && images.src) {
const { scale, moveX, moveY, moving, zooming } = state;
const style: CSSProperties = {
transitionDuration: zooming || moving ? '0s' : '.3s'
};

if (scale !== 1) {
const offsetX = moveX / scale;
const offsetY = moveY / scale;
style.transform = `scale(${scale}, ${scale}) translate(${offsetX}px, ${offsetY}px)`;
}

return style;
}

return style;
return {};
});

const maxMoveX = computed(() => {
Expand Down Expand Up @@ -258,10 +225,8 @@ export default create({
};

const onTouchEnd = (event: TouchEvent) => {
console.log('ontauchend');
let stopPropagation = false;

/* istanbul ignore else */
if (state.moving || state.zooming) {
stopPropagation = true;

Expand Down Expand Up @@ -291,30 +256,15 @@ export default create({
}
}

// eliminate tap delay on safari
preventDefault(event, stopPropagation);

checkTap();
touch.reset();
};

// 阻止
const preventDefault = (event: Event, isStopPropagation?: boolean) => {
if (typeof event.cancelable !== 'boolean' || event.cancelable) {
event.preventDefault();
}

if (isStopPropagation) {
event.stopPropagation();
}
};

const clamp = (num: number, min: number, max: number): number => Math.min(Math.max(num, min), max);

// 视频点击
const closeSwiper = (event: any) => {
console.log('关闭视频');
// event.preventDefault();
const closeSwiper = () => {
emit('close');
};

Expand Down
Loading