123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- /**
- * Created by xieli on 2018/7/12 0012.
- */
- import http from "api/http.js";
- import {apiDownloadResource} from '@/api/modules/oldApi'
- import {Message} from "element-ui"
- const mixins = {
- filters: {
- // 显示时间为 2021.07.22
- formatTime(time){
- if(time==='0001-01-01 00:00:00'||time==='0000-00-00 00:00:00'){
- return '--'
- }else{
- return time?time.replace(/-/g,'.'):''
- }
-
- },
- // 格式化金额 三位一个逗号
- formatPriceHasPoint(e){
- let str=e.toString()
- let num1='',num2=''
- if(str.indexOf(".")!=-1){
- num1=str.substring(0,str.indexOf("."))
- num2=str.substring(str.length,str.indexOf("."))
- if(Number(num2)<=0){
- num2=''
- }
- }else{
- num1=str
- }
- return num1.replace(/(?!^)(?=(\d{3})+$)/g, ',')+num2
- }
- },
- methods: {
- formatterColumn(row,column,cellvalue){
- return cellvalue ? http.dateFormatter(cellvalue) : '';
- },
- notHasTimeFormatter(row,column,cellvalue){
-
- return cellvalue ? http.dateFormatter(cellvalue,false) : '';
- },
- mixinsDateFormatter(date,type){
- if(!date) return "";
- return type === false ? http.dateFormatter(date, false) : http.dateFormatter(date);
- },
- numberFormatter(str,type=1){ // 0 文字在左侧 1 文字在右侧
- switch (str) {
- case '万':
- return (row,column,cellvalue) =>{
- return type ? `${this.division(cellvalue,10000)}${str}`:`${str}${this.division(cellvalue,10000)}`;
- };
- default:
- return (row,column,cellvalue) =>{
- return `${cellvalue}${str}`;
- };
- }
- },
- formatterTime(time){
- return http.dateFormatter(time);
- },
- /**
- * y 被除数
- * n 除数
- */
- division(y,n){ //除法
- if( y === '' || y===null || y===undefined){
- y = 0;
- }
- let a = String(y);
- let power = String(a).split('.')[1] ? String(a).split('.')[1].length : 0;
- let intY = y * Math.pow(10,power);
- let intN = n * Math.pow(10,power);
- return intY/intN;
- },
- prompt(msg) { //提示
- this.$message({
- message: msg,
- duration: 1000,
- });
- },
- notice(msg) {
- this.$message({
- message: msg,
- type: 'error',
- duration: 1000,
- });
- },
- success(msg) {
- this.$message({
- message: msg,
- type: 'success',
- duration: 1000,
- });
- },
- _handleFocus(){
- this.$nextTick(()=>{
- var a= document.getElementsByClassName('el-icon-arrow-right');
- a[1].removeAttribute('disabled');
- a[1].classList.remove('is-disabled');
- })
- },
- _sendCode(params,func){
- return new Promise( (resolve,reject)=>{
- this.$prompt('请输入验证码', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- inputValidator:(e)=>{
- if( e=='' || e==null ){
- return '验证码不能为空';
- }else{
- return true;
- }
- },
- beforeClose:(action,instance,done) => {
- if( action==='confirm' ){
- let newParams = Object.assign({},params,{VerifyCode:instance.inputValue});
- func(newParams).then(res=>{
- if( res.Ret==200 ){
- done();
- resolve(res);
- }
- })
- }else{
- done();
- }
- }
- }).then(({ value }) => {
-
- }).catch(() => {
- // this.$message({
- // type: 'info',
- // message: '取消输入'
- // });
- });
- })
- },
- // 下载文件
- handleDownloadResource(url,fileName,successCb,faileCb){
- const b=new http.Base64()
- const arr=url.split('/')
- const _fileName=arr[arr.length-1]
- const _fileType= _fileName.substring(_fileName.lastIndexOf(".") + 1)
- const fileNameTypeArr = fileName.split('.')
- const _fileNameTypeArr = _fileName.split('.')
- const fileNameType = fileNameTypeArr.length>1?fileNameTypeArr[fileNameTypeArr.length-1]:''
- const _fileNameType = _fileNameTypeArr.length>1?_fileNameTypeArr[_fileNameTypeArr.length-1]:''
- apiDownloadResource({
- FileName:/* fileName||_fileName */'',
- FileUrl:b.encode(url)
- }).then(res=>{
- console.log(res);
- const {status,data}=res
- if(status!=200){
- Message.warning('下载失败')
- return
- }
- //bus.$parseData(response);
- const content = data
- const blob = new Blob([content])
- if ('download' in document.createElement('a')) {
- const elink = document.createElement('a')
- elink.download = fileName+'.'+_fileType
- elink.style.display = 'none'
- elink.href = window.URL.createObjectURL(blob)
- document.body.appendChild(elink)
- elink.click()
- window.URL.revokeObjectURL(elink.href)
- document.body.removeChild(elink)
- } else {
- navigator.msSaveBlob(blob, fileName+'.'+_fileType)
- }
- successCb&&successCb()
- }).catch(()=>{
- Message.warning('下载失败')
- faileCb&&faileCb()
- })
- },
- //频度,单位 统一翻译
- //频度label显示,支持中英文
- getFrequencyTrans(frequency){
- const map = {
- '':this.$i18nt.t('Edb.FreAll.total'),//全部
- '日度':this.$i18nt.t('Edb.FreAll.day'),
- '周度':this.$i18nt.t('Edb.FreAll.week'),
- '旬度':this.$i18nt.t('Edb.FreAll.dekad'),
- '月度':this.$i18nt.t('Edb.FreAll.month'),
- '季度':this.$i18nt.t('Edb.FreAll.quarter'),
- '半年度':this.$i18nt.t('Edb.FreAll.half_year'),
- '年度':this.$i18nt.t('Edb.FreAll.year'),
- }
- return map[frequency]||''
- },
- //单位label显示,支持中英文
- getUnitTrans(unit){
- const map = {
- '无':this.$i18nt.t('Edb.UnitAll.u_null'),
- '万吨':this.$i18nt.t('Edb.UnitAll.wanton'),
- '亿元':this.$i18nt.t('Edb.UnitAll.u_bill'),
- '元':this.$i18nt.t('Edb.UnitAll.u_yuan'),
- '元/吨':this.$i18nt.t('Edb.UnitAll.yuan_ton'),
- '元/湿吨':this.$i18nt.t('Edb.UnitAll.yuan_wetton'),
- '千克':this.$i18nt.t('Edb.UnitAll.u_kg'),
- '吨':this.$i18nt.t('Edb.UnitAll.u_ton'),
- '短吨':this.$i18nt.t('Edb.UnitAll.short_ton'),
- '美元/吨':this.$i18nt.t('Edb.UnitAll.doll_ton'),
- '万平方千米':this.$i18nt.t('Edb.UnitAll.wan_skilo'),
- '美元/桶':this.$i18nt.t('Edb.UnitAll.doll_bar'),
- '美分/加仑':this.$i18nt.t('Edb.UnitAll.cent_gal'),
- '手':this.$i18nt.t('Edb.UnitAll.u_hand'),
- }
- return map[unit]||unit //若是自行输入的单位,直接返回
- }
- }
- }
- export { mixins }
|