first commit
This commit is contained in:
26
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/props.js
vendored
Normal file
26
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/props.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
const props = {
|
||||
/** 函数返回容器对应的 NodesRef 节点,将对应节点指定为组件的外部容器,滚动时组件会始终保持在容器范围内,当组件即将超出容器底部时,会返回原位置 */
|
||||
container: {
|
||||
type: Function
|
||||
},
|
||||
/** 是否禁用组件 */
|
||||
disabled: Boolean,
|
||||
/** 吸顶时与顶部的距离,单位`px` */
|
||||
offsetTop: {
|
||||
type: [String, Number],
|
||||
default: 0
|
||||
},
|
||||
/** 吸顶时的 z-index */
|
||||
zIndex: {
|
||||
type: Number,
|
||||
default: 99
|
||||
},
|
||||
/** 滚动时触发,scrollTop: 距离顶部位置,isFixed: 是否吸顶 */
|
||||
onScroll: {
|
||||
type: Function,
|
||||
default: () => ({})
|
||||
}
|
||||
};
|
||||
exports.props = props;
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/props.js.map
|
||||
126
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.js
vendored
Normal file
126
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.js
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
"use strict";
|
||||
const uni_modules_tdesignUniapp_components_common_src_instantiationDecorator = require("../common/src/instantiationDecorator.js");
|
||||
const uni_modules_tdesignUniapp_components_sticky_props = require("./props.js");
|
||||
const uni_modules_tdesignUniapp_components_common_config = require("../common/config.js");
|
||||
const uni_modules_tdesignUniapp_components_mixins_pageScroll = require("../mixins/page-scroll.js");
|
||||
const uni_modules_tdesignUniapp_components_common_utils = require("../common/utils.js");
|
||||
const uni_modules_tdesignUniapp_components_common_utils_wxs = require("../common/utils.wxs.js");
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const name = `${uni_modules_tdesignUniapp_components_common_config.prefix}-sticky`;
|
||||
const ContainerClass = `.${name}`;
|
||||
const _sfc_main = uni_modules_tdesignUniapp_components_common_src_instantiationDecorator.uniComponent({
|
||||
name,
|
||||
options: {
|
||||
styleIsolation: "shared"
|
||||
},
|
||||
externalClasses: [
|
||||
`${uni_modules_tdesignUniapp_components_common_config.prefix}-class`,
|
||||
`${uni_modules_tdesignUniapp_components_common_config.prefix}-class-content`
|
||||
],
|
||||
mixins: [uni_modules_tdesignUniapp_components_mixins_pageScroll.pageScrollMixin()],
|
||||
props: {
|
||||
...uni_modules_tdesignUniapp_components_sticky_props.props
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
prefix: uni_modules_tdesignUniapp_components_common_config.prefix,
|
||||
classPrefix: name,
|
||||
containerStyle: "",
|
||||
contentStyle: "",
|
||||
tools: uni_modules_tdesignUniapp_components_common_utils_wxs.tools
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
offsetTop: "onScroll",
|
||||
disabled: "onScroll",
|
||||
container: "onScroll"
|
||||
},
|
||||
mounted() {
|
||||
this.onScroll();
|
||||
},
|
||||
methods: {
|
||||
onScroll(event) {
|
||||
const { scrollTop } = event || {};
|
||||
const { container, offsetTop, disabled } = this;
|
||||
if (disabled) {
|
||||
this.setDataAfterDiff({
|
||||
isFixed: false,
|
||||
transform: 0
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.scrollTop = scrollTop || this.scrollTop;
|
||||
if (typeof container === "function") {
|
||||
Promise.all([uni_modules_tdesignUniapp_components_common_utils.getRect(this, ContainerClass), this.getContainerRect()]).then(([root, container2]) => {
|
||||
if (!root || !container2)
|
||||
return;
|
||||
if (offsetTop + root.height > container2.height + container2.top) {
|
||||
this.setDataAfterDiff({
|
||||
isFixed: false,
|
||||
transform: container2.height - root.height
|
||||
});
|
||||
} else if (offsetTop >= root.top) {
|
||||
this.setDataAfterDiff({
|
||||
isFixed: true,
|
||||
height: root.height,
|
||||
transform: 0
|
||||
});
|
||||
} else {
|
||||
this.setDataAfterDiff({ isFixed: false, transform: 0 });
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni_modules_tdesignUniapp_components_common_utils.getRect(this, ContainerClass).then((root) => {
|
||||
if (!root)
|
||||
return;
|
||||
if (offsetTop >= root.top) {
|
||||
this.setDataAfterDiff({ isFixed: true, height: root.height });
|
||||
this.transform = 0;
|
||||
} else {
|
||||
this.setDataAfterDiff({ isFixed: false });
|
||||
}
|
||||
});
|
||||
},
|
||||
setDataAfterDiff(data) {
|
||||
const { offsetTop } = this;
|
||||
const { containerStyle: prevContainerStyle, contentStyle: prevContentStyle } = this;
|
||||
const { isFixed, height, transform } = data;
|
||||
uni_modules_tdesignUniapp_components_common_utils.nextTick().then(() => {
|
||||
let containerStyle = "";
|
||||
let contentStyle = "";
|
||||
if (isFixed) {
|
||||
containerStyle += `height:${height}px;`;
|
||||
contentStyle += `position:fixed;top:${offsetTop}px;left:0;right:0;`;
|
||||
}
|
||||
if (transform) {
|
||||
const translate = `translate3d(0, ${transform}px, 0)`;
|
||||
contentStyle += `-webkit-transform:${translate};transform:${translate};`;
|
||||
}
|
||||
if (prevContainerStyle !== containerStyle || prevContentStyle !== contentStyle) {
|
||||
this.containerStyle = containerStyle;
|
||||
this.contentStyle = contentStyle;
|
||||
}
|
||||
this.$emit("scroll", {
|
||||
scrollTop: this.scrollTop,
|
||||
isFixed
|
||||
});
|
||||
});
|
||||
},
|
||||
getContainerRect() {
|
||||
const nodesRef = this.container();
|
||||
return new Promise((resolve) => nodesRef.boundingClientRect(resolve).exec());
|
||||
}
|
||||
}
|
||||
});
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return {
|
||||
a: common_vendor.n(_ctx.classPrefix + "__content " + _ctx.tClassContent),
|
||||
b: common_vendor.s(_ctx.tools._style(["z-index:" + _ctx.zIndex, _ctx.contentStyle])),
|
||||
c: common_vendor.n(_ctx.classPrefix + " " + _ctx.tClass),
|
||||
d: common_vendor.s(_ctx.tools._style(["z-index:" + _ctx.zIndex, _ctx.containerStyle, _ctx.customStyle]))
|
||||
};
|
||||
}
|
||||
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-1e0bcf5d"]]);
|
||||
wx.createComponent(Component);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.js.map
|
||||
4
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.json
vendored
Normal file
4
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
1
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.wxml
vendored
Normal file
1
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.wxml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<view class="{{['data-v-1e0bcf5d', c]}}" style="{{d}}"><view class="{{['data-v-1e0bcf5d', a]}}" style="{{b}}"><slot/></view></view>
|
||||
3
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.wxss
vendored
Normal file
3
unpackage/dist/dev/mp-weixin/uni_modules/tdesign-uniapp/components/sticky/sticky.wxss
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.t-sticky.data-v-1e0bcf5d {
|
||||
position: relative;
|
||||
}
|
||||
Reference in New Issue
Block a user