| import * as dd from 'dingtalk-jsapi' | 
| import sha1 from 'js-sha1' | 
| import store from '@/store' | 
|   | 
| /** | 
|  * 获取当前时间 时间戳 | 
|  * @returns {number} | 
|  */ | 
| export function getTimestamp () { | 
|     return new Date().getTime() | 
| } | 
|   | 
| /** | 
|  * 获取随机字符串 | 
|  * @param {number} len 可指定长度 | 
|  * @returns {string} | 
|  */ | 
| export function randomString (len: number): string { | 
|     len = len || 32 | 
|     let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678' | 
|     let maxPos = $chars.length | 
|     let pwd = '' | 
|     for (let i = 0; i < len; i++) { | 
|         pwd += $chars.charAt(Math.floor(Math.random() * maxPos)) | 
|     } | 
|     return pwd | 
| } | 
|   | 
| /** | 
|  * 拼接签名字符串 | 
|  * @param {string} ticket 通过access_token获取的jsapi_ticket | 
|  * @param {string} noncestr 自己生成的随机字符串 | 
|  * @param {string} timestamp 生成签名时的时间戳 | 
|  * @param {string} urlLink url地址获取code | 
|  * @param {string} return {*} | 
|  */ | 
| export function getSignature (ticket: String, noncestr: String, timestamp: String, urlLink: String): String { | 
|     let url = urlLink | 
|     let jsapi_ticket = `jsapi_ticket=${ticket}&noncestr=${noncestr}×tamp=${timestamp}&url=${url}` | 
|     return sha1(jsapi_ticket) | 
| } | 
|   | 
| /*** | 
|  * phoneRegular: 手机号验证 | 
|  * mailboxRegular: 邮箱验证 | 
|  * positiveInteger: 正整数 | 
|  * decimal: 小数(只支持四位小数) | 
|  * positiveIntegerDecimal: 正整数小数(最多四位小数) | 
|  * number:数字最多保留四位小数 | 
|  */ | 
| const REGULAR = { | 
|     phoneRegular: /^1[3456789]\d{9}$/, | 
|     mailboxRegular: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, | 
|     positiveInteger: /^[0-9]*[1-9][0-9]*$/, | 
|     decimal: /^0$|^[1-9]\d{0,15}$|^[1-9]\d{0,15}\.{1}\d{1,4}$|^0\.{1}\d{1,4}$/g, | 
|     positiveIntegerDecimal: /^([1-9][0-9]*|0)(\.[0-9]?[1-9][1-9][1-9])?$/, | 
|     number: /^\d+(?:\.\d{1,4})?$/ | 
| } | 
|   | 
| /*** | 
|  * 判断设备机型适配底部安全距离 | 
|  * true 是 | 
|  * false 否 | 
|  */ | 
| const equipment = () => { | 
|     // X XS, XS Max, XR,11, 11pro,11pro max,12mini,12, 12 pro,12 pro max | 
|     const xSeriesConfig = [ | 
|         { | 
|             devicePixelRatio: 3, | 
|             width: 375, | 
|             height: 812, | 
|         }, | 
|         { | 
|             devicePixelRatio: 3, | 
|             width: 414, | 
|             height: 896, | 
|         }, | 
|         { | 
|             devicePixelRatio: 2, | 
|             width: 414, | 
|             height: 896, | 
|         }, | 
|         { | 
|             devicePixelRatio: 3, | 
|             width: 315, | 
|             height: 812, | 
|         }, | 
|         { | 
|             devicePixelRatio: 3, | 
|             width: 390, | 
|             height: 844, | 
|         }, | 
|         { | 
|             devicePixelRatio: 3, | 
|             width: 428, | 
|             height: 926, | 
|         } | 
|     ]; | 
|     // h5 | 
|     if (typeof window !== 'undefined' && window) { | 
|         const isIOS = /iphone/gi.test(window.navigator.userAgent); | 
|         if (!isIOS) return false; | 
|         const { devicePixelRatio, screen } = window; | 
|         const { width, height } = screen; | 
|         return xSeriesConfig.some(item => item.devicePixelRatio === devicePixelRatio && item.width === width && item.height === height); | 
|     } | 
|     return false; | 
| } | 
|   | 
| /*** | 
|  * | 
|  * @param size 文件大小 | 
|  */ | 
| const sizeTostr = (size: any): string => { | 
|     let data = ""; | 
|     if (size < 0.1 * 1024) { //如果小于0.1KB转化成B | 
|         data = size.toFixed(2) + "B"; | 
|     } else if (size < 0.1 * 1024 * 1024) {//如果小于0.1MB转化成KB | 
|         data = (size / 1024).toFixed(2) + "KB"; | 
|     } else if (size < 0.1 * 1024 * 1024 * 1024) { //如果小于0.1GB转化成MB | 
|         data = (size / (1024 * 1024)).toFixed(2) + "MB"; | 
|     } else { //其他转化成GB | 
|         data = (size / (1024 * 1024 * 1024)).toFixed(2) + "GB"; | 
|     } | 
|     let sizestr = data + ""; | 
|     let len = sizestr.indexOf("\."); | 
|     let dec = sizestr.substr(len + 1, 2); | 
|     if (dec == "00") {//当小数点后为00时 去掉小数部分 | 
|         return sizestr.substring(0, len) + sizestr.substr(len + 3, 2); | 
|     } | 
|     return sizestr; | 
| } | 
|   | 
| /*** | 
|  * | 
|  * @param type 文件类型 | 
|  */ | 
| function judgmentType (type: string): boolean { | 
|     let arr = ['jpg', 'jpeg', 'png'] | 
|     // arr.includes(type) | 
|     let open: boolean = false | 
|     arr.forEach((item: string) => { | 
|         if (type === item) { | 
|             open = true | 
|         } | 
|     }) | 
|     return open; | 
| } | 
|   | 
| /*** | 
|  * | 
|  * @param time 日期 年月日 | 
|  */ | 
| function gsdate (time: any): string { | 
|     let date = new Date(time) | 
|     let y: any = date.getFullYear() | 
|     let m: any = date.getMonth() + 1 | 
|     m = m < 10 ? ('0' + m) : m | 
|     let d: any = date.getDate() | 
|     d = d < 10 ? ('0' + d) : d | 
|     return y + '-' + m + '-' + d; | 
| } | 
|   | 
| /*** | 
|  * | 
|  * @param time 日期 年月日时分秒 | 
|  * @param Sign 间隔 | 
|  */ | 
| function setTime (time: any, Sign: string): string { | 
|     let year= time.getFullYear(); | 
|     let month = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : `0${time.getMonth() + 1}`; | 
|     let day = time.getDate() >= 10 ? time.getDate() : `0${time.getDate()}`; | 
|     let hour = time.getHours() >= 10 ? time.getHours() : `0${time.getHours()}`; | 
|     let minute = time.getMinutes() >= 10 ? time.getMinutes() : `0${time.getMinutes()}`; | 
|     let second = time.getSeconds() >= 10 ? time.getSeconds() : `0${time.getSeconds()}`; | 
|     return [year, Sign, month , Sign, day, ' ', hour , ':', minute, ':', second ].join(''); | 
| } | 
|   | 
| /*** | 
|  * | 
|  * @param time 日期 年月日时分秒 | 
|  * @param Sign 间隔 | 
|  */ | 
| function setTimeO (time: any, Sign: string): string { | 
|     let year = time.getFullYear(); | 
|     let month = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : `0${time.getMonth() + 1}`; | 
|     let day = time.getDate() >= 10 ? time.getDate() : `0${time.getDate()}`; | 
|     let hour = time.getHours() >= 10 ? time.getHours() : `0${time.getHours()}`; | 
|     let minute = time.getMinutes() >= 10 ? time.getMinutes() : `0${time.getMinutes()}`; | 
|     let second = time.getSeconds() >= 10 ? time.getSeconds() : `0${time.getSeconds()}`; | 
|     return [year, Sign, month , Sign, day, ' ', hour , ':', minute, ':', '00' ].join(''); | 
| } | 
|   | 
|   | 
| /*** | 
|  * 返回 true:顶顶端 | 
|  * 返回 false:h5端 | 
|  */ | 
| function judgmentPlatform (): boolean { | 
|     // alert(store.state.env) | 
|     // alert(store.state.env !== 'DD') | 
|     return store.state.env === 'DD' | 
|     // return dd.env.platform !== 'notInDingTalk'; | 
| } | 
|   | 
| /***REGULAR | 
|  * | 
|  * @param auth 需要验证的权限 | 
|  */ | 
| function auth (auth: string): boolean { | 
|     const configPermissions = auth | 
|     if (store.state.userInfo.permissions === {}) {      // 没有权限 | 
|         return false | 
|     } | 
|     const authList = store.state.userInfo.permissions   // 获取所有权限 | 
|     const isShow = authList.indexOf(configPermissions) | 
|     return isShow !== -1; | 
| } | 
|   | 
| /*** | 
|  * DOCUMENT_TYPE: 出入库单据 - 单据类型 | 
|  */ | 
| const DOCUMENT_TYPE = { | 
|     1: { | 
|         name: '车间领料' | 
|     }, | 
|     2: { | 
|         name: '机台备料' | 
|     }, | 
|     3: { | 
|         name: '车间转库' | 
|     }, | 
|     4: { | 
|         name: '完工入库' | 
|     }, | 
|     5: { | 
|         name: '计划领料' | 
|     }, | 
|     6: { | 
|         name: '外协领料' | 
|     }, | 
|     7: { | 
|         name: '外协完工转库' | 
|     }, | 
|     8: { | 
|         name: '成品入库' | 
|     }, | 
|     9: { | 
|         name: '成品转库' | 
|     }, | 
|     10: { | 
|         name: '让步放行入库' | 
|     }, | 
|     11: { | 
|         name: '让步放行转库' | 
|     }, | 
|     12: { | 
|         name: '客返返修领料' | 
|     }, | 
|     13: { | 
|         name: '客返返修入库' | 
|     }, | 
|     14: { | 
|         name: '跨组织转库' | 
|     }, | 
|     15: { | 
|         name: '工单投料(出库),工单产出(入)' | 
|     }, | 
|     16: { | 
|         name: '销售出库' | 
|     }, | 
|     17: { | 
|         name: '让步销售' | 
|     } | 
| } | 
|   | 
| export { | 
|     REGULAR, | 
|     gsdate, | 
|     setTime, | 
|     judgmentPlatform, | 
|     auth, | 
|     judgmentType, | 
|     sizeTostr, | 
|     equipment, | 
|     setTimeO, | 
|     DOCUMENT_TYPE | 
| } |