nyzy_vue/src/views/gateway/mixins/getwayMixin.js

92 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-04-26 13:51:46 +08:00
/**
*/
import { deleteAction, getAction,downFile,getFileAccessHttpUrl } from '@/api/manage'
import * as utils from "@/views/gateway/utils";
export const getwayMixin = {
data(){
return {
utils
}
},
created() {
},
computed:{
commonData(){
return this.$store.state.app.gatewayCommonData;
}
},
methods:{
//根据不同语言使用不同字段,有限使用
$tf(data,field){
if(!data) return '';
if(!field) return '';
let content = data[field + utils.getLocale()];
if(!content){
content = data[field];
}
return content;
},
//翻译并且去除html标签
$tfnm(data,field,fontNum = 0){
let txt = this.$tf(data,field);
if(!txt) return '';
txt = txt.replace(/<\/?.+?>/g,"").replace(/ /g,"");
let div = document.createElement('div');
div.innerHTML = txt;
txt = div.innerText;
if(fontNum){
if(txt.length > fontNum){
txt = txt.substring(0,fontNum) + '...'
}
}
return txt;
},
//获取图片,根据语言选择
$tImg(...data){
return this.getImgView(this.$tf(...data));
},
$tFiles(...data){
let fileUrls = this.$tf(...data);
if(!fileUrls){ return []}
return fileUrls.split(',').map(x => getFileAccessHttpUrl(x));
},
//简便跳页
$to(name,query,replace=false){
// if(name == this.$router.name){
// }
2022-07-05 14:56:18 +08:00
// this.$router.push({name,query,replace})
// window.open('','_blank')
const{ href } = this.$router.resolve({name,query,replace});
if(name.indexOf('detailedPage')>-1){
window.open(href,'_blank');
}else{
this.$router.push({name,query,replace})
}
2022-07-05 14:56:18 +08:00
2022-04-26 13:51:46 +08:00
},
/* 图片预览 */
getImgView(text){
if(text && text.indexOf(",")>0){
text = text.substring(0,text.indexOf(","))
}
return getFileAccessHttpUrl(text)
},
/* 文件下载 */
// update--autor:lvdandan-----date:20200630------for修改下载文件方法名uploadFile改为downloadFile------
downloadFile(text){
if(!text){
this.$message.warning("未知的文件")
return;
}
if(text.indexOf(",")>0){
text = text.substring(0,text.indexOf(","))
}
let url = getFileAccessHttpUrl(text)
window.open(url);
},
}
}