xzs-mysql/source/wx/xzs-student/component/iView/cell/index.js
2020-07-16 14:12:31 +08:00

87 lines
2.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 });
}
}
});