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.
92 lines
1.9 KiB
92 lines
1.9 KiB
5 years ago
|
function processObj(obj) {
|
||
|
for (var key in obj) {
|
||
|
if (!obj.hasOwnProperty(key) || typeof obj[key] != "object")
|
||
|
continue
|
||
|
processObj(obj[key]);
|
||
|
obj[key].__proto__ = obj;
|
||
|
}
|
||
|
}
|
||
|
const app = getApp();
|
||
|
const configMap={
|
||
|
text: "${course_act_type}",
|
||
|
type: "${course_act_type}",
|
||
|
color: "black",
|
||
|
CourseAttendance:{
|
||
|
text:"课堂签到开始了",
|
||
|
type:"签到",
|
||
|
color:"#09ad42"
|
||
|
},
|
||
|
HomeworkCommon:{
|
||
|
practice:{
|
||
|
type: "实训作业",
|
||
|
color: "#ce223e",
|
||
|
url:"{shixun_homework}?homework_id=${course_act_id}"
|
||
|
},
|
||
|
normal: {
|
||
|
type:"普通作业",
|
||
|
color:"#CC6633"
|
||
|
},
|
||
|
text: "${container_name}",
|
||
|
type:"作业",
|
||
|
color:"#ac3f8a"
|
||
|
},
|
||
|
CourseMessage: {
|
||
|
type:"课堂申请",
|
||
|
text:"申请加入课堂",
|
||
|
color:"#3333FF"
|
||
|
},
|
||
|
Course: {
|
||
|
type:"创建课堂",
|
||
|
text:"大家快来加入课堂学习吧",
|
||
|
color:"#33DDAA"
|
||
|
}
|
||
|
|
||
|
}
|
||
|
processObj(configMap);
|
||
|
|
||
|
|
||
|
function get(obj, key) {
|
||
|
if (typeof obj == "object" && key in obj)
|
||
|
return obj[key];
|
||
|
else
|
||
|
return {__proto__:obj};
|
||
|
}
|
||
|
|
||
|
|
||
|
function format(str, values){
|
||
|
return str.replace(/\$\{(.*?)\}/, function (match, key) {
|
||
|
return values[key] || "";
|
||
|
});
|
||
|
}
|
||
|
|
||
|
Component({
|
||
|
properties: {
|
||
|
data:{
|
||
|
type:Object,
|
||
|
observer:function(data){
|
||
|
let config = get(configMap, data.course_act_type);
|
||
|
config = get(config, data.container_type);
|
||
|
this.config = config;
|
||
|
data.text = format(config.text, data);
|
||
|
data.type = format(config.type, data);
|
||
|
data.color = config.color;
|
||
|
data.time = data.created_at.replace(/^.+ /,"");
|
||
|
this.setData(data);
|
||
|
//console.log(data);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
data: {
|
||
|
eduImgDir:global.config.eduImgDir
|
||
|
},
|
||
|
methods: {
|
||
|
onTap(){
|
||
|
let {url} = this.config;
|
||
|
if(!url) return;
|
||
|
url = format(url, this.data);
|
||
|
app.navigateTo({url});
|
||
|
}
|
||
|
}
|
||
|
})
|