// component/sidebar/sidebar.js Component({ options: { multipleSlots: true, // 在组件定义时的选项中启用多slot支持 addGlobalClass: true }, properties: { maskClass: { // 遮罩层class type: String, value: '' }, extClass: { // 弹出窗 class type: String, value: '' }, maskClosable: { // 点击遮罩 关闭 actionsheet type: Boolean, value: true }, mask: { // 是否需要 遮罩层 type: Boolean, value: true }, show: { // 是否开启 actionsheet type: Boolean, value: false }, menus: { // 一级菜单 列表 type: Array, value: [], }, items: { // 二级菜单 列表 type: Array, value: [], } }, data: { selectedIndex: [0, 0], tempSelectedIndex: [0, 0] }, methods: { _groupChange(e) { // 支持 一维数组 写法 if (e.length > 0 && typeof e[0] !== 'string' && !(e[0] instanceof Array)) { this.setData({ actions: [this.data.actions] }); } }, buttonTap(e) { const { value, groupindex, index } = e.currentTarget.dataset; this.triggerEvent('actiontap', { value, groupindex, index }); }, closeActionSheet(e) { this.setData({ tempSelectedIndex: this.data.selectedIndex }) const { type } = e.currentTarget.dataset; if (this.data.maskClosable || type) { // 点击 action 里面的 取消 this.setData({ show: false }); // 关闭回调事件 this.triggerEvent('close'); } }, chooseMenu(e) { const { index } = e.currentTarget.dataset; this.setData({ tempSelectedIndex: [index, 0] }) }, chooseItem(e) { const { index } = e.currentTarget.dataset; this.setData({ 'tempSelectedIndex[1]': index }) }, submit() { this.setData({ selectedIndex: this.data.tempSelectedIndex }) this.triggerEvent('submit', this.data.selectedIndex); this.setData({ show: false }); } } })