From d1448cb0ef10f358bb7bddb4e1ec268515e0b787 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 15 七月 2025 11:46:57 +0800 Subject: [PATCH] 项目初始化 --- uni_modules/uview-ui/components/u-list/u-list.vue | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 159 insertions(+), 0 deletions(-) diff --git a/uni_modules/uview-ui/components/u-list/u-list.vue b/uni_modules/uview-ui/components/u-list/u-list.vue new file mode 100644 index 0000000..513decc --- /dev/null +++ b/uni_modules/uview-ui/components/u-list/u-list.vue @@ -0,0 +1,159 @@ +<template> + <!-- #ifdef APP-NVUE --> + <list + class="u-list" + :enableBackToTop="enableBackToTop" + :loadmoreoffset="lowerThreshold" + :showScrollbar="showScrollbar" + :style="[listStyle]" + :offset-accuracy="Number(offsetAccuracy)" + @scroll="onScroll" + @loadmore="scrolltolower" + > + <slot /> + </list> + <!-- #endif --> + <!-- #ifndef APP-NVUE --> + <scroll-view + class="u-list" + :scroll-into-view="scrollIntoView" + :style="[listStyle]" + scroll-y + :scroll-top="Number(scrollTop)" + :lower-threshold="Number(lowerThreshold)" + :upper-threshold="Number(upperThreshold)" + :show-scrollbar="showScrollbar" + :enable-back-to-top="enableBackToTop" + :scroll-with-animation="scrollWithAnimation" + @scroll="onScroll" + @scrolltolower="scrolltolower" + @scrolltoupper="scrolltoupper" + > + <view :style="{ + paddingTop: `${offset}px` + }"> + <slot /> + </view> + </scroll-view> + <!-- #endif --> +</template> + +<script> + import props from './props.js'; + // #ifdef APP-NVUE + const dom = uni.requireNativePlugin('dom') + // #endif + /** + * List 鍒楄〃 + * @description 璇ョ粍浠朵负楂樻�ц兘鍒楄〃缁勪欢 + * @tutorial https://www.uviewui.com/components/list.html + * @property {Boolean} showScrollbar 鎺у埗鏄惁鍑虹幇婊氬姩鏉★紝浠卬vue鏈夋晥 锛堥粯璁� false 锛� + * @property {String 锝� Number} lowerThreshold 璺濆簳閮ㄥ灏戞椂瑙﹀彂scrolltolower浜嬩欢 锛堥粯璁� 50 锛� + * @property {String 锝� Number} upperThreshold 璺濋《閮ㄥ灏戞椂瑙﹀彂scrolltoupper浜嬩欢锛岄潪nvue鏈夋晥 锛堥粯璁� 0 锛� + * @property {String 锝� Number} scrollTop 璁剧疆绔栧悜婊氬姩鏉′綅缃紙榛樿 0 锛� + * @property {String 锝� Number} offsetAccuracy 鎺у埗 onscroll 浜嬩欢瑙﹀彂鐨勯鐜囷紝浠卬vue鏈夋晥锛堥粯璁� 10 锛� + * @property {Boolean} enableFlex 鍚敤 flexbox 甯冨眬銆傚紑鍚悗锛屽綋鍓嶈妭鐐瑰0鏄庝簡display: flex灏变細鎴愪负flex container锛屽苟浣滅敤浜庡叾瀛╁瓙鑺傜偣锛屼粎寰俊灏忕▼搴忔湁鏁堬紙榛樿 false 锛� + * @property {Boolean} pagingEnabled 鏄惁鎸夊垎椤垫ā寮忔樉绀篖ist锛岋紙榛樿 false 锛� + * @property {Boolean} scrollable 鏄惁鍏佽List婊氬姩锛堥粯璁� true 锛� + * @property {String} scrollIntoView 鍊煎簲涓烘煇瀛愬厓绱爄d锛坕d涓嶈兘浠ユ暟瀛楀紑澶达級 + * @property {Boolean} scrollWithAnimation 鍦ㄨ缃粴鍔ㄦ潯浣嶇疆鏃朵娇鐢ㄥ姩鐢昏繃娓� 锛堥粯璁� false 锛� + * @property {Boolean} enableBackToTop iOS鐐瑰嚮椤堕儴鐘舵�佹爮銆佸畨鍗撳弻鍑绘爣棰樻爮鏃讹紝婊氬姩鏉¤繑鍥為《閮紝鍙寰俊灏忕▼搴忔湁鏁� 锛堥粯璁� false 锛� + * @property {String 锝� Number} height 鍒楄〃鐨勯珮搴� 锛堥粯璁� 0 锛� + * @property {String 锝� Number} width 鍒楄〃瀹藉害 锛堥粯璁� 0 锛� + * @property {String 锝� Number} preLoadScreen 鍒楄〃鍓嶅悗棰勬覆鏌撶殑灞忔暟锛�1浠h〃涓�涓睆骞曠殑楂樺害锛�1.5浠h〃1涓崐灞忓箷楂樺害 锛堥粯璁� 1 锛� + * @property {Object} customStyle 瀹氫箟闇�瑕佺敤鍒扮殑澶栭儴鏍峰紡 + * + * @example <u-list @scrolltolower="scrolltolower"></u-list> + */ + export default { + name: 'u-list', + mixins: [uni.$u.mpMixin, uni.$u.mixin,props], + watch: { + scrollIntoView(n) { + this.scrollIntoViewById(n) + } + }, + data() { + return { + // 璁板綍鍐呴儴婊氬姩鐨勮窛绂� + innerScrollTop: 0, + // vue涓嬶紝scroll-view鍦ㄤ笂鎷夊姞杞芥椂鐨勫亸绉诲�� + offset: 0, + sys: uni.$u.sys() + } + }, + computed: { + listStyle() { + const style = {}, + addUnit = uni.$u.addUnit + if (this.width != 0) style.width = addUnit(this.width) + if (this.height != 0) style.height = addUnit(this.height) + // 濡傛灉娌℃湁瀹氫箟鍒楄〃楂樺害锛屽垯榛樿浣跨敤灞忓箷楂樺害 + if (!style.height) style.height = addUnit(this.sys.windowHeight, 'px') + return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle)) + } + }, + provide() { + return { + uList: this + } + }, + created() { + this.refs = [] + this.children = [] + this.anchors = [] + }, + mounted() {}, + methods: { + updateOffsetFromChild(top) { + this.offset = top + }, + onScroll(e) { + let scrollTop = 0 + // #ifdef APP-NVUE + scrollTop = e.contentOffset.y + // #endif + // #ifndef APP-NVUE + scrollTop = e.detail.scrollTop + // #endif + this.innerScrollTop = scrollTop + this.$emit('scroll', Math.abs(scrollTop)) + }, + scrollIntoViewById(id) { + // #ifdef APP-NVUE + // 鏍规嵁id鍙傛暟锛屾壘鍒版墍鏈塽-list-item涓尮閰嶇殑鑺傜偣锛屽啀閫氳繃dom妯″潡婊氬姩鍒板搴旂殑浣嶇疆 + const item = this.refs.find(item => item.$refs[id] ? true : false) + dom.scrollToElement(item.$refs[id], { + // 鏄惁闇�瑕佹粴鍔ㄥ姩鐢� + animated: this.scrollWithAnimation + }) + // #endif + }, + // 婊氬姩鍒板簳閮ㄨЕ鍙戜簨浠� + scrolltolower(e) { + uni.$u.sleep(30).then(() => { + this.$emit('scrolltolower') + }) + }, + // #ifndef APP-NVUE + // 婊氬姩鍒板簳閮ㄦ椂瑙﹀彂锛岄潪nvue鏈夋晥 + scrolltoupper(e) { + uni.$u.sleep(30).then(() => { + this.$emit('scrolltoupper') + // 杩欎竴鍙ュ緢閲嶈锛岃兘缁濆淇濊瘉鍦ㄦ�у姛鑳介殰纰嶇殑webview锛屾粴鍔ㄦ潯鍒伴《鏃讹紝鍙栨秷鍋忕Щ鍊硷紝璁╅〉闈㈢疆椤� + this.offset = 0 + }) + } + // #endif + }, + } +</script> + +<style lang="scss" scoped> + @import "../../libs/css/components.scss"; + + .u-list { + @include flex(column); + + } +</style> -- Gitblit v1.9.3