提交 f7f4602a 编写于 作者: D DCloud_LXH

feat: navigator

上级 e1d3fd44
......@@ -2,9 +2,7 @@
<uni-navigator
v-if="hoverClass && hoverClass !== 'none'"
:class="[hovering ? hoverClass : '']"
@touchstart="_hoverTouchStart"
@touchend="_hoverTouchEnd"
@touchcancel="_hoverTouchCancel"
v-bind="binding"
@click="_onClick"
>
<slot />
......@@ -14,33 +12,26 @@
</uni-navigator>
</template>
<script>
import hover from '../../mixins/hover'
import { useHover } from "../../helpers/useHover";
const OPEN_TYPES = [
'navigate',
'redirect',
'switchTab',
'reLaunch',
'navigateBack',
]
const OPEN_TYPES = ["navigate", "redirect", "switchTab", "reLaunch", "navigateBack"];
export default {
name: 'Navigator',
mixins: [hover],
name: "Navigator",
props: {
hoverClass: {
type: String,
default: 'navigator-hover',
default: "navigator-hover",
},
url: {
type: String,
default: '',
default: "",
},
openType: {
type: String,
default: 'navigate',
default: "navigate",
validator(value) {
return ~OPEN_TYPES.indexOf(value)
return ~OPEN_TYPES.indexOf(value);
},
},
delta: {
......@@ -49,7 +40,7 @@ export default {
},
hoverStartTime: {
type: [Number, String],
default: 20,
default: 50,
},
hoverStayTime: {
type: [Number, String],
......@@ -57,50 +48,63 @@ export default {
},
exists: {
type: String,
default: '',
default: "",
},
hoverStopPropagation: {
type: Boolean,
default: false,
},
},
methods: {
_onClick($event) {
if (this.openType !== 'navigateBack' && !this.url) {
if (this.openType !== "navigateBack" && !this.url) {
console.error(
'<navigator/> should have url attribute when using navigateTo, redirectTo, reLaunch or switchTab'
)
return
"<navigator/> should have url attribute when using navigateTo, redirectTo, reLaunch or switchTab"
);
return;
}
switch (this.openType) {
case 'navigate':
case "navigate":
uni.navigateTo({
url: this.url,
})
break
case 'redirect':
});
break;
case "redirect":
uni.redirectTo({
url: this.url,
exists: this.exists,
})
break
case 'switchTab':
});
break;
case "switchTab":
uni.switchTab({
url: this.url,
})
break
case 'reLaunch':
});
break;
case "reLaunch":
uni.reLaunch({
url: this.url,
})
break
case 'navigateBack':
});
break;
case "navigateBack":
uni.navigateBack({
delta: this.delta,
})
break
});
break;
default:
break
break;
}
},
},
}
setup(props) {
const { hovering, binding } = useHover(props);
return {
hovering,
binding,
};
},
};
</script>
......@@ -1206,73 +1206,6 @@ function setupApp(comp) {
}
});
}
var hover = {
data() {
return {
hovering: false
};
},
props: {
hoverClass: {
type: String,
default: "none"
},
hoverStopPropagation: {
type: Boolean,
default: false
},
hoverStartTime: {
type: [Number, String],
default: 50
},
hoverStayTime: {
type: [Number, String],
default: 400
}
},
methods: {
_hoverTouchStart(evt) {
if (evt._hoverPropagationStopped) {
return;
}
if (!this.hoverClass || this.hoverClass === "none" || this.disabled) {
return;
}
if (evt.touches.length > 1) {
return;
}
if (this.hoverStopPropagation) {
evt._hoverPropagationStopped = true;
}
this._hoverTouch = true;
this._hoverStartTimer = setTimeout(() => {
this.hovering = true;
if (!this._hoverTouch) {
this._hoverReset();
}
}, this.hoverStartTime);
},
_hoverTouchEnd(evt) {
this._hoverTouch = false;
if (this.hovering) {
this._hoverReset();
}
},
_hoverReset() {
requestAnimationFrame(() => {
clearTimeout(this._hoverStayTimer);
this._hoverStayTimer = setTimeout(() => {
this.hovering = false;
}, this.hoverStayTime);
});
},
_hoverTouchCancel(evt) {
this._hoverTouch = false;
this.hovering = false;
clearTimeout(this._hoverStartTimer);
}
}
};
var subscriber = {
mounted() {
this._toggleListeners("subscribe", this.id);
......@@ -4386,16 +4319,9 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
], 16);
}
_sfc_main$7.render = _sfc_render$7;
const OPEN_TYPES = [
"navigate",
"redirect",
"switchTab",
"reLaunch",
"navigateBack"
];
const OPEN_TYPES = ["navigate", "redirect", "switchTab", "reLaunch", "navigateBack"];
const _sfc_main$6 = {
name: "Navigator",
mixins: [hover],
props: {
hoverClass: {
type: String,
......@@ -4418,7 +4344,7 @@ const _sfc_main$6 = {
},
hoverStartTime: {
type: [Number, String],
default: 20
default: 50
},
hoverStayTime: {
type: [Number, String],
......@@ -4427,6 +4353,10 @@ const _sfc_main$6 = {
exists: {
type: String,
default: ""
},
hoverStopPropagation: {
type: Boolean,
default: false
}
},
methods: {
......@@ -4464,21 +4394,26 @@ const _sfc_main$6 = {
break;
}
}
},
setup(props2) {
const {hovering, binding} = useHover(props2);
return {
hovering,
binding
};
}
};
function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
return $props.hoverClass && $props.hoverClass !== "none" ? (vue.openBlock(), vue.createBlock("uni-navigator", {
return $props.hoverClass && $props.hoverClass !== "none" ? (vue.openBlock(), vue.createBlock("uni-navigator", vue.mergeProps({
key: 0,
class: [_ctx.hovering ? $props.hoverClass : ""],
onTouchstart: _cache[1] || (_cache[1] = (...args) => _ctx._hoverTouchStart && _ctx._hoverTouchStart(...args)),
onTouchend: _cache[2] || (_cache[2] = (...args) => _ctx._hoverTouchEnd && _ctx._hoverTouchEnd(...args)),
onTouchcancel: _cache[3] || (_cache[3] = (...args) => _ctx._hoverTouchCancel && _ctx._hoverTouchCancel(...args)),
onClick: _cache[4] || (_cache[4] = (...args) => $options._onClick && $options._onClick(...args))
}, [
class: [$setup.hovering ? $props.hoverClass : ""]
}, $setup.binding, {
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick && $options._onClick(...args))
}), [
vue.renderSlot(_ctx.$slots, "default")
], 34)) : (vue.openBlock(), vue.createBlock("uni-navigator", {
], 16)) : (vue.openBlock(), vue.createBlock("uni-navigator", {
key: 1,
onClick: _cache[5] || (_cache[5] = (...args) => $options._onClick && $options._onClick(...args))
onClick: _cache[2] || (_cache[2] = (...args) => $options._onClick && $options._onClick(...args))
}, [
vue.renderSlot(_ctx.$slots, "default")
]));
......
......@@ -4794,73 +4794,6 @@ function setupApp(comp) {
}
});
}
var hover = {
data() {
return {
hovering: false
};
},
props: {
hoverClass: {
type: String,
default: "none"
},
hoverStopPropagation: {
type: Boolean,
default: false
},
hoverStartTime: {
type: [Number, String],
default: 50
},
hoverStayTime: {
type: [Number, String],
default: 400
}
},
methods: {
_hoverTouchStart(evt) {
if (evt._hoverPropagationStopped) {
return;
}
if (!this.hoverClass || this.hoverClass === "none" || this.disabled) {
return;
}
if (evt.touches.length > 1) {
return;
}
if (this.hoverStopPropagation) {
evt._hoverPropagationStopped = true;
}
this._hoverTouch = true;
this._hoverStartTimer = setTimeout(() => {
this.hovering = true;
if (!this._hoverTouch) {
this._hoverReset();
}
}, this.hoverStartTime);
},
_hoverTouchEnd(evt) {
this._hoverTouch = false;
if (this.hovering) {
this._hoverReset();
}
},
_hoverReset() {
requestAnimationFrame(() => {
clearTimeout(this._hoverStayTimer);
this._hoverStayTimer = setTimeout(() => {
this.hovering = false;
}, this.hoverStayTime);
});
},
_hoverTouchCancel(evt) {
this._hoverTouch = false;
this.hovering = false;
clearTimeout(this._hoverStartTimer);
}
}
};
var subscriber = {
mounted() {
this._toggleListeners("subscribe", this.id);
......@@ -8835,16 +8768,9 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
], 16);
}
_sfc_main$7.render = _sfc_render$7;
const OPEN_TYPES = [
"navigate",
"redirect",
"switchTab",
"reLaunch",
"navigateBack"
];
const OPEN_TYPES = ["navigate", "redirect", "switchTab", "reLaunch", "navigateBack"];
const _sfc_main$6 = {
name: "Navigator",
mixins: [hover],
props: {
hoverClass: {
type: String,
......@@ -8867,7 +8793,7 @@ const _sfc_main$6 = {
},
hoverStartTime: {
type: [Number, String],
default: 20
default: 50
},
hoverStayTime: {
type: [Number, String],
......@@ -8876,6 +8802,10 @@ const _sfc_main$6 = {
exists: {
type: String,
default: ""
},
hoverStopPropagation: {
type: Boolean,
default: false
}
},
methods: {
......@@ -8913,21 +8843,26 @@ const _sfc_main$6 = {
break;
}
}
},
setup(props2) {
const {hovering, binding} = useHover(props2);
return {
hovering,
binding
};
}
};
function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
return $props.hoverClass && $props.hoverClass !== "none" ? (openBlock(), createBlock("uni-navigator", {
return $props.hoverClass && $props.hoverClass !== "none" ? (openBlock(), createBlock("uni-navigator", mergeProps({
key: 0,
class: [_ctx.hovering ? $props.hoverClass : ""],
onTouchstart: _cache[1] || (_cache[1] = (...args) => _ctx._hoverTouchStart && _ctx._hoverTouchStart(...args)),
onTouchend: _cache[2] || (_cache[2] = (...args) => _ctx._hoverTouchEnd && _ctx._hoverTouchEnd(...args)),
onTouchcancel: _cache[3] || (_cache[3] = (...args) => _ctx._hoverTouchCancel && _ctx._hoverTouchCancel(...args)),
onClick: _cache[4] || (_cache[4] = (...args) => $options._onClick && $options._onClick(...args))
}, [
class: [$setup.hovering ? $props.hoverClass : ""]
}, $setup.binding, {
onClick: _cache[1] || (_cache[1] = (...args) => $options._onClick && $options._onClick(...args))
}), [
renderSlot(_ctx.$slots, "default")
], 34)) : (openBlock(), createBlock("uni-navigator", {
], 16)) : (openBlock(), createBlock("uni-navigator", {
key: 1,
onClick: _cache[5] || (_cache[5] = (...args) => $options._onClick && $options._onClick(...args))
onClick: _cache[2] || (_cache[2] = (...args) => $options._onClick && $options._onClick(...args))
}, [
renderSlot(_ctx.$slots, "default")
]));
......
......@@ -5,7 +5,6 @@ import vue from '@vitejs/plugin-vue'
import jscc from 'rollup-plugin-jscc'
import strip from '@rollup/plugin-strip'
import replace from '@rollup/plugin-replace'
import minimatch from 'minimatch'
import { stripOptions } from '@dcloudio/uni-cli-shared'
import { isCustomElement } from '../uni-shared'
......@@ -40,7 +39,7 @@ const rollupPlugins = [
// 该插件限制了不能以__开头
_NODE_JS_: FORMAT === 'cjs' ? 1 : 0,
},
// exclude: ['pako.esm.mjs'],
// 忽略 pako 内部条件编译
exclude: [resolve('../../node_modules/pako/**')],
}),
]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册