web-vue2
Version:
web ui for vue2
85 lines (84 loc) • 3.07 kB
JavaScript
const i18nRegex = /^[\[]((\w|\d|[.%_-])+)[\]]$/;
/**
* 已正式加入框架体系应用
* marked by deleteelf 20210819
*/
export default {
methods: {
adapterUrl(url,data=null,withoutEncoding=false,noFoundedEmpty=true,token=false) {
if(url) {
if(data!=null){
url = url.urlFormat(data,withoutEncoding,noFoundedEmpty);
this.$core.debug().log("格式化后的地址",url);
}
if(token)
return this.$core.adapterUrl(url,this.$store.state.api.axios.baseURL,false, this.$store.state.user.token);
return this.$core.adapterUrl(url,this.$store.state.api.axios.baseURL);
}
return "";
},hasRichText(text){
return /^[<][-\w]+([ ].*)*[>].*[<][/][-\w]+[>]$/.test(text);
},$_i18n(text){
if (i18nRegex.test(text)) {
return this.$i18n.t(i18nRegex.exec(text)[1]);
}
return text;
},placeholderAdapter(item) {
if (!this.form||!this.form.readonly) {
switch (item.type) {
case "text":
case "editor":
case "textarea":
return this.$_i18n(item.remark) || (this.checkDisable(item) ?
this.$_i18n(item.name) + this.$t("form.system_build") :
this.$t("form.write") + this.$_i18n(item.name));
case "select":
case "dropdownchecklist":
case "selectTree":
return this.$t("form.select");
case "autocomplete":
case "autocomplete_remote":
return this.$t("form.autocomplete");
default:
return this.$_i18n(item.remark);
}
} else {
return "";
}
},checkDisable(item) {
if (this.options&&this.options.params&&this.options.params.readonly) {
return true;
}else if(item.disable===true) {//业务干预 //某些情况下,需要由代码业务逻辑来控制禁用
return true;
}else if(item.readonly===true){//业务干预 //某些情况下,需要由代码业务逻辑来控制只读
return true;
} else if(item.modReadonly!=null||item.addReadonly!=null){
if (this.options.params.id) {
return item.modReadonly;
} else {
return item.addReadonly;
}
}
return false;
},setControlTitle(item) {
switch (item.type) {
case "text":
case "editor":
case "textarea":
return this.$_i18n(item.remark) || (this.checkDisable(item) ?
"" : this.$t("form.write") + this.$_i18n(item.name));
default:
return this.$_i18n(item.remark) || (this.checkDisable(item) ?
"" : this.$t("form.select") + this.$_i18n(item.name));
}
},$_page_message(result) {
if(result.msg) {//部分场景不需要提示时,会关闭掉提示,采用的方式是删除msg的内容
this.$notify({
title: (result.code===0 ? "成功" : "失败"),
duration: 5000, message: result.msg,
type: (result.code===0 ? "success" : "error")
});
}
},
}
}