You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.4 KiB
70 lines
1.4 KiB
Component({
|
|
properties: {
|
|
gridname: {
|
|
type: String,
|
|
value: "",
|
|
},
|
|
},
|
|
|
|
data: {
|
|
showText: "",
|
|
},
|
|
|
|
observers: {
|
|
gridname(val) {
|
|
this.computeShowText();
|
|
},
|
|
},
|
|
|
|
lifetimes: {
|
|
ready() {
|
|
this.init();
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
init() {
|
|
// console.log("日期显示组件初始化完成");
|
|
},
|
|
|
|
computeShowText() {
|
|
const { gridname } = this.data;
|
|
let arr = gridname.split('-')
|
|
let temp = ""
|
|
for (let i = 0; i < arr.length; i++) {
|
|
if (i == (arr.length - 1)) {
|
|
temp += this.substr(i, arr[i])
|
|
} else {
|
|
temp = temp + this.substr(i, arr[i]) + "-"
|
|
}
|
|
}
|
|
this.setData({ showText: temp });
|
|
},
|
|
substr(index: Number, str: string) {
|
|
console.log(index, str)
|
|
let temp = ""
|
|
if (index == 0) {
|
|
if (str.length > 3) {
|
|
temp = str.substring(0,3)+'...'
|
|
} else {
|
|
temp = str
|
|
}
|
|
|
|
} else if (index == 1) {
|
|
if (str.length > 5) {
|
|
temp = str.substring(0,3)+'...'+str.substring(str.length-2)
|
|
} else {
|
|
temp = str
|
|
}
|
|
|
|
} else if (index == 2) {
|
|
if (str.length > 5) {
|
|
temp = str.substring(0,2)+'...'+str.substring(str.length-3)
|
|
} else {
|
|
temp = str
|
|
}
|
|
}
|
|
return temp
|
|
}
|
|
},
|
|
});
|
|
|