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-collapse/u-collapse.vue | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 90 insertions(+), 0 deletions(-) diff --git a/uni_modules/uview-ui/components/u-collapse/u-collapse.vue b/uni_modules/uview-ui/components/u-collapse/u-collapse.vue new file mode 100644 index 0000000..fc188a2 --- /dev/null +++ b/uni_modules/uview-ui/components/u-collapse/u-collapse.vue @@ -0,0 +1,90 @@ +<template> + <view class="u-collapse"> + <u-line v-if="border"></u-line> + <slot /> + </view> +</template> + +<script> + import props from './props.js'; + /** + * collapse 鎶樺彔闈㈡澘 + * @description 閫氳繃鎶樺彔闈㈡澘鏀剁撼鍐呭鍖哄煙 + * @tutorial https://www.uviewui.com/components/collapse.html + * @property {String | Number | Array} value 褰撳墠灞曞紑闈㈡澘鐨刵ame锛岄潪鎵嬮鐞存ā寮忥細[<string | number>]锛屾墜椋庣惔妯″紡锛歴tring | number + * @property {Boolean} accordion 鏄惁鎵嬮鐞存ā寮忥紙 榛樿 false 锛� + * @property {Boolean} border 鏄惁鏄剧ず澶栬竟妗� ( 榛樿 true 锛� + * @event {Function} change 褰撳墠婵�娲婚潰鏉垮睍寮�鏃惰Е鍙�(濡傛灉鏄墜椋庣惔妯″紡锛屽弬鏁癮ctiveNames绫诲瀷涓篠tring锛屽惁鍒欎负Array) + * @example <u-collapse></u-collapse> + */ + export default { + name: "u-collapse", + mixins: [uni.$u.mpMixin, uni.$u.mixin,props], + watch: { + needInit() { + this.init() + } + }, + created() { + this.children = [] + }, + computed: { + needInit() { + // 閫氳繃computed锛屽悓鏃剁洃鍚琣ccordion鍜寁alue鍊肩殑鍙樺寲 + // 鍐嶉�氳繃watch鍘绘墽琛宨nit()鏂规硶锛岃繘琛屽啀涓�娆$殑鍒濆鍖� + return [this.accordion, this.value] + } + }, + watch: { + // 褰撶埗缁勪欢闇�瑕佸瓙缁勪欢闇�瑕佸叡浜殑鍙傛暟鍙戠敓浜嗗彉鍖栵紝鎵嬪姩閫氱煡瀛愮粍浠� + parentData() { + if (this.children.length) { + this.children.map(child => { + // 鍒ゆ柇瀛愮粍浠�(u-checkbox)濡傛灉鏈塽pdateParentData鏂规硶鐨勮瘽锛屽氨灏辨墽琛�(鎵ц鐨勭粨鏋滄槸瀛愮粍浠堕噸鏂颁粠鐖剁粍浠舵媺鍙栦簡鏈�鏂扮殑鍊�) + typeof(child.updateParentData) === 'function' && child.updateParentData() + }) + } + }, + }, + methods: { + // 閲嶆柊鍒濆鍖栦竴娆″唴閮ㄧ殑鎵�鏈夊瓙鍏冪礌 + init() { + this.children.map(child => { + child.init() + }) + }, + /** + * collapse-item琚偣鍑绘椂瑙﹀彂锛岀敱collapse缁熶竴澶勭悊鍚勫瓙缁勪欢鐨勭姸鎬� + * @param {Object} target 琚搷浣滅殑闈㈡澘鐨勫疄渚� + */ + onChange(target) { + let changeArr = [] + this.children.map((child, index) => { + // 濡傛灉鏄墜椋庣惔妯″紡锛屽皢鍏朵粬鐨勬姌鍙犻潰鏉挎敹璧锋潵 + if (this.accordion) { + child.expanded = child === target ? !target.expanded : false + child.setContentAnimate() + } else { + if(child === target) { + child.expanded = !child.expanded + child.setContentAnimate() + } + } + // 鎷兼帴change浜嬩欢涓紝鏁扮粍鍏冪礌鐨勭姸鎬� + changeArr.push({ + // 濡傛灉娌℃湁瀹氫箟name灞炴�э紝鍒欓粯璁よ繑鍥炵粍浠剁殑index绱㈠紩 + name: child.name || index, + status: child.expanded ? 'open' : 'close' + }) + }) + + this.$emit('change', changeArr) + this.$emit(target.expanded ? 'open' : 'close', target.name) + } + } + } +</script> + +<style lang="scss" scoped> + @import "../../libs/css/components.scss"; +</style> -- Gitblit v1.9.3