| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import CryptoJS from 'crypto-js'
- import { ORDER_STATUS } from '@/const'
- const payStatus = {
- WAIT_PAY: {
- label: '待支付',
- type: 'primary'
- },
- PAYED: {
- label: '已支付',
- type: 'success'
- },
- CLOSED: {
- label: '已关闭',
- type: 'info'
- },
- CANCELED: {
- label: '已取消',
- type: 'info'
- },
- REFUNDED: {
- label: '已退款',
- type: 'danger'
- },
- REFUNDING: {
- label: '退款中',
- type: 'warning'
- }
- }
- export function getPayStatus (str, attr = 'label') {
- return payStatus[str] ? payStatus[str][attr] : ''
- }
- export function getOrderStatus (str, attr = 'label') {
- return ORDER_STATUS[str] ? ORDER_STATUS[str][attr] : ''
- }
- export function parseTime (time, cFormat) {
- if (arguments.length === 0) {
- return null
- }
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
- let date
- if (typeof time === 'object') {
- date = time
- } else {
- if (('' + time).length === 10) time = parseInt(time) * 1000
- date = new Date(time)
- }
- const formatObj = {
- y: date.getFullYear(),
- m: date.getMonth() + 1,
- d: date.getDate(),
- h: date.getHours(),
- i: date.getMinutes(),
- s: date.getSeconds(),
- a: date.getDay()
- }
- const timeStr = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
- let value = formatObj[key]
- if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
- if (result.length > 0 && value < 10) {
- value = '0' + value
- }
- return value || 0
- })
- return timeStr
- }
- export function param2Obj (url) {
- const search = url.split('?')[1]
- if (!search) {
- return {}
- }
- return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
- }
- // 设置表格总计行高亮
- export function totalRowClassName ({row, rowIndex}) {
- for (let key in row) {
- if (row[key] === '总计') {
- return 'tableTotalRow'
- }
- if ((row[key] + '').indexOf('小计') > -1) {
- return 'tableTotalRow tableTotalRow1'
- }
- if ((row[key] + '').indexOf('总计') > -1) {
- return 'tableTotalRow tableTotalRow2'
- }
- }
- }
- const desKey = 'fnFACVwC'
- const key = CryptoJS.enc.Hex.parse('TgxRS8DG65EjK8cpKTiPAw==') // 密钥
- const iv = CryptoJS.enc.Hex.parse('') // 偏移量
- // aes加密
- export function encrypt (word) {
- let encrypted = ''
- if (typeof word === 'string') {
- const key = CryptoJS.enc.Utf8.parse(desKey)
- console.log(word, desKey, 'aaaa')
- encrypted = CryptoJS.DES.encrypt(word, key, {
- mode: CryptoJS.mode.ECB,
- padding: CryptoJS.pad.Pkcs7
- })
- return encrypted.toString()
- // const srcs = CryptoJS.enc.Hex.parse(word)
- // // var encryptedBase64Str = CryptoJS.enc.Base64.stringify(srcs)
- // encrypted = CryptoJS.AES.encrypt(srcs, key, {
- // mode: CryptoJS.mode.ECB,
- // padding: CryptoJS.pad.ZeroPadding
- // })
- } else if (typeof word === 'object') {
- // 对象格式的转成json字符串
- const data = JSON.stringify(word)
- const srcs = CryptoJS.enc.Utf8.parse(data)
- encrypted = CryptoJS.AES.encrypt(srcs, key, {
- iv: iv,
- mode: CryptoJS.mode.ECB,
- padding: CryptoJS.pad.Pkcs7
- })
- }
- return encrypted.ciphertext.toString()
- }
- // aes解密
- export function decrypt (word) {
- const encryptedHexStr = CryptoJS.enc.Hex.parse(word)
- const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
- const decrypt = CryptoJS.AES.decrypt(srcs, key, {
- iv: iv,
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.Pkcs7
- })
- const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
- return decryptedStr.toString()
- }
|