ASR/miniprogram/dist/cell/index.js

87 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-08-31 16:55:41 +00:00
const warn = (msg, getValue) => {
console.warn(msg);
console.log('接受到的值为:', getValue);
};
Component({
externalClasses: ['i-class'],
options: {
multipleSlots: true
},
relations: {
'../cell-group/index': {
type: 'parent'
}
},
properties: {
// 左侧标题
title: {
type: String
},
// 标题下方的描述信息
label: {
type: String
},
// 右侧内容
value: {
type: String
},
// 只有点击 footer 区域才触发 tab 事件
onlyTapFooter: {
type: Boolean
},
// 是否展示右侧箭头并开启尝试以 url 跳转
isLink: {
type: null,
value: ''
},
// 链接类型,可选值为 navigateToredirectToswitchTabreLaunch
linkType: {
type: String,
value: 'navigateTo'
},
url: {
type: String,
value: ''
}
},
data: {
isLastCell: true
},
methods: {
navigateTo () {
const { url } = this.data;
const type = typeof this.data.isLink;
this.triggerEvent('click', {});
if (!this.data.isLink || !url || url === 'true' || url === 'false') return;
if (type !== 'boolean' && type !== 'string') {
warn('isLink 属性值必须是一个字符串或布尔值', this.data.isLink);
return;
}
if (['navigateTo', 'redirectTo', 'switchTab', 'reLaunch'].indexOf(this.data.linkType) === -1) {
warn('linkType 属性可选值为 navigateToredirectToswitchTabreLaunch', this.data.linkType);
return;
}
wx[this.data.linkType].call(wx, {url});
},
handleTap () {
if (!this.data.onlyTapFooter) {
this.navigateTo();
}
},
updateIsLastCell (isLastCell) {
this.setData({ isLastCell });
}
}
});