index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /**
  2. * Created by xieli on 2018/7/12 0012.
  3. */
  4. import http from "api/http.js";
  5. import {apiDownloadResource} from '@/api/modules/oldApi'
  6. import {Message} from "element-ui"
  7. const mixins = {
  8. filters: {
  9. // 显示时间为 2021.07.22
  10. formatTime(time){
  11. if(time==='0001-01-01 00:00:00'||time==='0000-00-00 00:00:00'){
  12. return '--'
  13. }else{
  14. return time?time.replace(/-/g,'.'):''
  15. }
  16. },
  17. // 格式化金额 三位一个逗号
  18. formatPriceHasPoint(e){
  19. let str=e.toString()
  20. let num1='',num2=''
  21. if(str.indexOf(".")!=-1){
  22. num1=str.substring(0,str.indexOf("."))
  23. num2=str.substring(str.length,str.indexOf("."))
  24. if(Number(num2)<=0){
  25. num2=''
  26. }
  27. }else{
  28. num1=str
  29. }
  30. return num1.replace(/(?!^)(?=(\d{3})+$)/g, ',')+num2
  31. }
  32. },
  33. methods: {
  34. formatterColumn(row,column,cellvalue){
  35. return cellvalue ? http.dateFormatter(cellvalue) : '';
  36. },
  37. notHasTimeFormatter(row,column,cellvalue){
  38. return cellvalue ? http.dateFormatter(cellvalue,false) : '';
  39. },
  40. mixinsDateFormatter(date,type){
  41. if(!date) return "";
  42. return type === false ? http.dateFormatter(date, false) : http.dateFormatter(date);
  43. },
  44. numberFormatter(str,type=1){ // 0 文字在左侧 1 文字在右侧
  45. switch (str) {
  46. case '万':
  47. return (row,column,cellvalue) =>{
  48. return type ? `${this.division(cellvalue,10000)}${str}`:`${str}${this.division(cellvalue,10000)}`;
  49. };
  50. default:
  51. return (row,column,cellvalue) =>{
  52. return `${cellvalue}${str}`;
  53. };
  54. }
  55. },
  56. formatterTime(time){
  57. return http.dateFormatter(time);
  58. },
  59. /**
  60. * y 被除数
  61. * n 除数
  62. */
  63. division(y,n){ //除法
  64. if( y === '' || y===null || y===undefined){
  65. y = 0;
  66. }
  67. let a = String(y);
  68. let power = String(a).split('.')[1] ? String(a).split('.')[1].length : 0;
  69. let intY = y * Math.pow(10,power);
  70. let intN = n * Math.pow(10,power);
  71. return intY/intN;
  72. },
  73. prompt(msg) { //提示
  74. this.$message({
  75. message: msg,
  76. duration: 1000,
  77. });
  78. },
  79. notice(msg) {
  80. this.$message({
  81. message: msg,
  82. type: 'error',
  83. duration: 1000,
  84. });
  85. },
  86. success(msg) {
  87. this.$message({
  88. message: msg,
  89. type: 'success',
  90. duration: 1000,
  91. });
  92. },
  93. _handleFocus(){
  94. this.$nextTick(()=>{
  95. var a= document.getElementsByClassName('el-icon-arrow-right');
  96. a[1].removeAttribute('disabled');
  97. a[1].classList.remove('is-disabled');
  98. })
  99. },
  100. _sendCode(params,func){
  101. return new Promise( (resolve,reject)=>{
  102. this.$prompt('请输入验证码', '提示', {
  103. confirmButtonText: '确定',
  104. cancelButtonText: '取消',
  105. inputValidator:(e)=>{
  106. if( e=='' || e==null ){
  107. return '验证码不能为空';
  108. }else{
  109. return true;
  110. }
  111. },
  112. beforeClose:(action,instance,done) => {
  113. if( action==='confirm' ){
  114. let newParams = Object.assign({},params,{VerifyCode:instance.inputValue});
  115. func(newParams).then(res=>{
  116. if( res.Ret==200 ){
  117. done();
  118. resolve(res);
  119. }
  120. })
  121. }else{
  122. done();
  123. }
  124. }
  125. }).then(({ value }) => {
  126. }).catch(() => {
  127. // this.$message({
  128. // type: 'info',
  129. // message: '取消输入'
  130. // });
  131. });
  132. })
  133. },
  134. // 下载文件
  135. handleDownloadResource(url,fileName,successCb,faileCb){
  136. const b=new http.Base64()
  137. const arr=url.split('/')
  138. const _fileName=arr[arr.length-1]
  139. const _fileType= _fileName.substring(_fileName.lastIndexOf(".") + 1)
  140. const fileNameTypeArr = fileName.split('.')
  141. const _fileNameTypeArr = _fileName.split('.')
  142. const fileNameType = fileNameTypeArr.length>1?fileNameTypeArr[fileNameTypeArr.length-1]:''
  143. const _fileNameType = _fileNameTypeArr.length>1?_fileNameTypeArr[_fileNameTypeArr.length-1]:''
  144. apiDownloadResource({
  145. FileName:/* fileName||_fileName */'',
  146. FileUrl:b.encode(url)
  147. }).then(res=>{
  148. console.log(res);
  149. const {status,data}=res
  150. if(status!=200){
  151. Message.warning('下载失败')
  152. return
  153. }
  154. //bus.$parseData(response);
  155. const content = data
  156. const blob = new Blob([content])
  157. if ('download' in document.createElement('a')) {
  158. const elink = document.createElement('a')
  159. elink.download = fileName+'.'+_fileType
  160. elink.style.display = 'none'
  161. elink.href = window.URL.createObjectURL(blob)
  162. document.body.appendChild(elink)
  163. elink.click()
  164. window.URL.revokeObjectURL(elink.href)
  165. document.body.removeChild(elink)
  166. } else {
  167. navigator.msSaveBlob(blob, fileName+'.'+_fileType)
  168. }
  169. successCb&&successCb()
  170. }).catch(()=>{
  171. Message.warning('下载失败')
  172. faileCb&&faileCb()
  173. })
  174. },
  175. //频度,单位 统一翻译
  176. //频度label显示,支持中英文
  177. getFrequencyTrans(frequency){
  178. const map = {
  179. '':this.$i18nt.t('Edb.FreAll.total'),//全部
  180. '日度':this.$i18nt.t('Edb.FreAll.day'),
  181. '周度':this.$i18nt.t('Edb.FreAll.week'),
  182. '旬度':this.$i18nt.t('Edb.FreAll.dekad'),
  183. '月度':this.$i18nt.t('Edb.FreAll.month'),
  184. '季度':this.$i18nt.t('Edb.FreAll.quarter'),
  185. '半年度':this.$i18nt.t('Edb.FreAll.half_year'),
  186. '年度':this.$i18nt.t('Edb.FreAll.year'),
  187. }
  188. return map[frequency]||''
  189. },
  190. //单位label显示,支持中英文
  191. getUnitTrans(unit){
  192. const map = {
  193. '无':this.$i18nt.t('Edb.UnitAll.u_null'),
  194. '万吨':this.$i18nt.t('Edb.UnitAll.wanton'),
  195. '亿元':this.$i18nt.t('Edb.UnitAll.u_bill'),
  196. '元':this.$i18nt.t('Edb.UnitAll.u_yuan'),
  197. '元/吨':this.$i18nt.t('Edb.UnitAll.yuan_ton'),
  198. '元/湿吨':this.$i18nt.t('Edb.UnitAll.yuan_wetton'),
  199. '千克':this.$i18nt.t('Edb.UnitAll.u_kg'),
  200. '吨':this.$i18nt.t('Edb.UnitAll.u_ton'),
  201. '短吨':this.$i18nt.t('Edb.UnitAll.short_ton'),
  202. '美元/吨':this.$i18nt.t('Edb.UnitAll.doll_ton'),
  203. '万平方千米':this.$i18nt.t('Edb.UnitAll.wan_skilo'),
  204. '美元/桶':this.$i18nt.t('Edb.UnitAll.doll_bar'),
  205. '美分/加仑':this.$i18nt.t('Edb.UnitAll.cent_gal'),
  206. '手':this.$i18nt.t('Edb.UnitAll.u_hand'),
  207. }
  208. return map[unit]||unit //若是自行输入的单位,直接返回
  209. }
  210. }
  211. }
  212. export { mixins }