zhaoxiaoqiang1
2026-01-04 f1d30d03186c79ca2cbcfe60d6d2ce7d73fba97b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * @Author: lixiong
 * @Date: 2019-09-06 10:53:36
 * @Last Modified by: Pengjiantian
 * @Last Modified time: 2020-06-23 16:19:05
 */
import dayjs from 'dayjs'
import { fMoney, getEnvInfo, emptyStr } from '@/utils/utils'
 
let newWindow = null
 
function getOrigin(useLocal = false) {
  const { mode, webPrefix } = getEnvInfo()
  const fix = useLocal ? webPrefix : ''
  if (mode === 'development' && !useLocal) {
    return `http://10.10.16.114${fix}`
  }
  return `${location.origin}${fix}`
}
 
// vue 插件
export default {
  install(Vue, options) {
    Vue.mixin({
      filters: {
        // 金额格式化
        fMoney,
        fRecord(val, header = {}) {
          const { isMoney } = header
          if (isMoney) {
            return fMoney(val)
          }
          return typeof val === 'undefined' || String(val).trim() === ''
            ? emptyStr
            : val
        }
      },
      methods: {
        /**
         * 格式化时间
         * @param {number|object} value 时间戳或时间对象
         * @param {string} formate 格式化字符串
         */
        $formateDate(value, formate = 'YYYY/MM/DD') {
          if (!isNaN(value)) {
            return dayjs(new Date(Number(value))).format(formate)
          }
          if (value instanceof Date) {
            return dayjs(value).format(formate)
          }
          return value
        },
        /**
         * 拷贝字符串到剪切板
         * @param {string} text 待拷贝文本
         */
        $copyText(text, isTip = true, tipText = '拷贝成功!') {
          return new Promise((resolve, reject) => {
            const failedMsg = '拷贝失败!'
            const textarea = document.createElement('textarea')
            textarea.style.position = 'fixed'
            textarea.style.top = 0
            textarea.style.left = 0
            textarea.style.border = 'none'
            textarea.style.outline = 'none'
            textarea.style.resize = 'none'
            textarea.style.background = 'transparent'
            textarea.style.color = 'transparent'
 
            textarea.value = `${text}`
            document.body.appendChild(textarea)
            textarea.select()
            try {
              const isSucc = document.execCommand('copy')
              document.body.removeChild(textarea)
              if (isSucc) {
                if (isTip) {
                  this.$message.info(tipText)
                }
                resolve()
              } else {
                if (isTip) {
                  this.$message.warning(failedMsg)
                }
                reject(new Error(failedMsg))
              }
            } catch (err) {
              document.body.removeChild(textarea)
              if (isTip) {
                this.$message.warning(failedMsg)
              }
              reject(err)
            }
          })
        },
        $goDetail(item) {
          let {
            applySerialno = '',
            detailFlowNo: flowno,
            customerId = '',
            detailObjectType: objectType,
            detailOccurtype: occurtype
          } = item
          location.href = `${getOrigin()}/cts-web/#/comprehensiveTransaction/loanDetail/${applySerialno}?occurType=${occurtype ||
            ''}&flowno=${flowno || ''}&objectType=${objectType ||
            ''}&customerID=${customerId}&from=mal`
        },
        $goPhoto(info, callback) {
          // const params = Object.keys(info).reduce((pre, curr) => {
          //   const temp = `${curr}=${info[curr]}`
          //   return pre ? `${pre}&${temp}` : temp
          // }, '')
          if (newWindow) {
            newWindow.close()
          }
          // this.$openWindow(`${getOrigin(true)}/#/photoViewer?${params}`, true)
          this.$openWindow('/photoViewer', info, true)
 
          // 若图片展示页面删除图片,则通知刷新列表图片
          this.$getMessage(callback)
        },
        $openWindow(path, info = '', isListener = false) {
          let params =
            typeof info === 'string'
              ? info
              : Object.keys(info).reduce((pre, curr) => {
                const temp = `${curr}=${info[curr]}`
                return pre ? `${pre}&${temp}` : temp
              }, '')
          params =
            path.includes('?') || params.includes('?') ? params : `?${params}`
          let href = `${getOrigin(true)}/#${path}${params}&isHideBack=${1}`
          const framAttrs =
            'height=700px, width=800px, top=100px,left=400px, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no'
          if (isListener) {
            newWindow = window.open(href, 'newWindow', framAttrs)
          } else {
            href = `${path}${params}&isHideBack=${1}`
            window.open(href, 'tempWindow', framAttrs)
          }
        },
        // 订阅预览页消息
        $getMessage(callback) {
          // 避免重复绑定
          this.$removeMessage()
          // this.isAddEvent = true
          newWindow.addEventListener(
            'message',
            (info = {}) => {
              try {
                let { data } = info
                data = data || {}
                // data可能为空字符串,对象,或字符串对象
                data = typeof data === 'string' ? JSON.parse(data) : data
                const { type } = data
                // 如果在预览也删除图片,则刷新当前数据
                if (typeof callback === 'function') {
                  callback(type)
                }
              } catch (e) {
                console.log(e)
              }
            },
            false
          )
        },
        $removeMessage() {
          const { newWindow, $getMessage } = this
          if (newWindow) {
            newWindow.removeEventListener('message', $getMessage, false)
          }
        }
      }
    })
 
    Vue.prototype.$utils = {
      fMoney
    }
 
    // 全局信息
    Vue.prototype.$projectInfo = {
      ...getEnvInfo()
    }
  }
}