初始提交
This commit is contained in:
204
libs/chat.js
Normal file
204
libs/chat.js
Normal file
@@ -0,0 +1,204 @@
|
||||
import define from '@/utils/define'
|
||||
import jnpf from '@/utils/jnpf'
|
||||
import {
|
||||
useChatStoreWithOut
|
||||
} from '@/store/modules/chat'
|
||||
import {
|
||||
useUserStore
|
||||
} from '@/store/modules/user'
|
||||
|
||||
const chatStore = useChatStoreWithOut()
|
||||
const userStore = useUserStore()
|
||||
let socketTask = false
|
||||
const Socket = {
|
||||
conTime: 0,
|
||||
initSocket() {
|
||||
try {
|
||||
const token = uni.getStorageSync('token') || ''
|
||||
const sys = uni.getStorageSync('systemInfo') || ''
|
||||
const userInfo = uni.getStorageSync('userInfo') || {}
|
||||
socketTask = uni.connectSocket({
|
||||
url: define.webSocketUrl + '/' + encodeURIComponent(token),
|
||||
// #ifdef APP
|
||||
header: {
|
||||
'User-Agent': sys
|
||||
},
|
||||
// #endif
|
||||
success() {
|
||||
setTimeout(() => chatStore.setSocket(socketTask), 0)
|
||||
},
|
||||
});
|
||||
socketTask.onMessage((res) => {
|
||||
let dataStr = res.data;
|
||||
const data = JSON.parse(dataStr)
|
||||
let options = {
|
||||
cover: false,
|
||||
sound: 'system',
|
||||
title: data.title
|
||||
};
|
||||
switch (data.method) {
|
||||
case "initMessage": //初始化
|
||||
const msgInfo = {
|
||||
messageText: data.messageDefaultText || '暂无数据',
|
||||
messageCount: data.unreadMessageCount + data.unreadSystemMessageCount < 0 ?
|
||||
0 : data.unreadMessageCount + data.unreadSystemMessageCount + data
|
||||
.unreadScheduleCount,
|
||||
messageDate: data.messageDefaultTime || 0,
|
||||
}
|
||||
let badgeNum = data.unreadTotalCount
|
||||
for (let i = 0; i < data.unreadNums.length; i++) {
|
||||
badgeNum = badgeNum + data.unreadNums[i].unreadNum
|
||||
}
|
||||
chatStore.setBadgeNum(badgeNum)
|
||||
chatStore.setMsgInfo(msgInfo)
|
||||
break;
|
||||
case "Online": //在线用户
|
||||
|
||||
break;
|
||||
case "Offline": //离线用户
|
||||
|
||||
break;
|
||||
case "sendMessage": //发送消息
|
||||
chatStore.sendMessage(data)
|
||||
break;
|
||||
case "receiveMessage": //接收消息
|
||||
// #ifdef APP
|
||||
plus.push.createMessage('你有一条聊天消息', {
|
||||
...data,
|
||||
messageType: 100
|
||||
}, options);
|
||||
// #endif
|
||||
chatStore.receiveMessage(data)
|
||||
break;
|
||||
case "messageList": //消息列表
|
||||
chatStore.getMessageList(data)
|
||||
break;
|
||||
case "messagePush": //消息推送
|
||||
// #ifdef APP
|
||||
let content = "公告"
|
||||
if (data.messageType == 2) content = '流程'
|
||||
if (data.messageType == 3) content = '系统'
|
||||
if (data.messageType == 4) content = '日程'
|
||||
uni.createPushMessage(res => {})
|
||||
uniCloud.callFunction({
|
||||
name: 'jnpfPush', // 云函数名称
|
||||
data: {
|
||||
"push_clientid": uni.getStorageSync('push_clientid'),
|
||||
"title": data.title,
|
||||
"content": `你有一条${content}消息`,
|
||||
"payload": {
|
||||
"data": {
|
||||
...data
|
||||
},
|
||||
"options": {
|
||||
...options
|
||||
}
|
||||
}
|
||||
},
|
||||
success: res => {},
|
||||
fail: err => {}
|
||||
});
|
||||
// #endif
|
||||
chatStore.messagePush(data)
|
||||
break;
|
||||
case "closeSocket": //断开websocket连接
|
||||
Socket.close()
|
||||
break;
|
||||
case "logout":
|
||||
uni.showToast({
|
||||
title: data.msg || '登录已过期',
|
||||
icon: 'none',
|
||||
complete: () => {
|
||||
setTimeout(() => {
|
||||
userStore.resetToken()
|
||||
setTimeout(() => {
|
||||
Socket.close()
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
}, 500)
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
break;
|
||||
case "refresh":
|
||||
uni.showToast({
|
||||
title: '您的权限发生变更,正在刷新界面!',
|
||||
icon: 'none',
|
||||
complete: () => {
|
||||
setTimeout(() => {
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}, 500)
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
|
||||
socketTask.onOpen((data) => {
|
||||
Socket.conTime = 0
|
||||
const msg = JSON.stringify({
|
||||
method: "OnConnection",
|
||||
token,
|
||||
mobileDevice: true,
|
||||
systemId: userInfo.appSystemId
|
||||
});
|
||||
Socket.sendMsg(msg)
|
||||
})
|
||||
|
||||
socketTask.onClose((data) => {
|
||||
socketTask = false
|
||||
chatStore.setSocket(null)
|
||||
})
|
||||
|
||||
socketTask.onError((data) => {
|
||||
chatStore.setSocket(null)
|
||||
setTimeout(() => {
|
||||
Socket.conTime += 1
|
||||
if (Socket.conTime <= 10) {
|
||||
if (Socket.conTime >= 3) {
|
||||
uni.showToast({
|
||||
title: 'IM通讯正在连接:' + '连接第' + Socket.conTime + '次!稍后...',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
Socket.reConnect();
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: 'IM通讯连接失败,联系服务器管理员',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}, 10000)
|
||||
})
|
||||
} catch (e) {}
|
||||
},
|
||||
sendMsg(data) {
|
||||
if (socketTask === false) return Socket.reConnect()
|
||||
let content = data;
|
||||
socketTask.send({
|
||||
data: content,
|
||||
complete(e) {}
|
||||
})
|
||||
},
|
||||
//重连
|
||||
reConnect() {
|
||||
Socket.initSocket()
|
||||
},
|
||||
close() {
|
||||
socketTask.close({
|
||||
complete(e) {
|
||||
socketTask = false
|
||||
chatStore.setSocket(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
export default Socket
|
||||
396
libs/color-typeConversion.js
Normal file
396
libs/color-typeConversion.js
Normal file
@@ -0,0 +1,396 @@
|
||||
const conversion = {
|
||||
colorList: [{
|
||||
r: 244,
|
||||
g: 67,
|
||||
b: 54,
|
||||
a: 1
|
||||
}, {
|
||||
r: 233,
|
||||
g: 30,
|
||||
b: 99,
|
||||
a: 1
|
||||
}, {
|
||||
r: 156,
|
||||
g: 39,
|
||||
b: 176,
|
||||
a: 1
|
||||
}, {
|
||||
r: 103,
|
||||
g: 58,
|
||||
b: 183,
|
||||
a: 1
|
||||
}, {
|
||||
r: 63,
|
||||
g: 81,
|
||||
b: 181,
|
||||
a: 1
|
||||
}, {
|
||||
r: 33,
|
||||
g: 150,
|
||||
b: 243,
|
||||
a: 1
|
||||
}, {
|
||||
r: 3,
|
||||
g: 169,
|
||||
b: 244,
|
||||
a: 1
|
||||
}, {
|
||||
r: 0,
|
||||
g: 188,
|
||||
b: 212,
|
||||
a: 1
|
||||
}, {
|
||||
r: 0,
|
||||
g: 150,
|
||||
b: 136,
|
||||
a: 1
|
||||
}, {
|
||||
r: 76,
|
||||
g: 175,
|
||||
b: 80,
|
||||
a: 1
|
||||
}, {
|
||||
r: 139,
|
||||
g: 195,
|
||||
b: 74,
|
||||
a: 1
|
||||
}, {
|
||||
r: 205,
|
||||
g: 220,
|
||||
b: 57,
|
||||
a: 1
|
||||
}, {
|
||||
r: 255,
|
||||
g: 235,
|
||||
b: 59,
|
||||
a: 1
|
||||
}, {
|
||||
r: 255,
|
||||
g: 193,
|
||||
b: 7,
|
||||
a: 1
|
||||
}, {
|
||||
r: 255,
|
||||
g: 152,
|
||||
b: 0,
|
||||
a: 1
|
||||
}, {
|
||||
r: 255,
|
||||
g: 87,
|
||||
b: 34,
|
||||
a: 1
|
||||
}, {
|
||||
r: 121,
|
||||
g: 85,
|
||||
b: 72,
|
||||
a: 1
|
||||
}, {
|
||||
r: 158,
|
||||
g: 158,
|
||||
b: 158,
|
||||
a: 1
|
||||
}, {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 0.5
|
||||
}, {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 0
|
||||
}, ],
|
||||
hsv2rgb(h, s, v) {
|
||||
h = this.bound01(h, 360) * 6;
|
||||
s = this.bound01(s, 100);
|
||||
v = this.bound01(v, 100);
|
||||
const i = Math.floor(h);
|
||||
const f = h - i;
|
||||
const p = v * (1 - s);
|
||||
const q = v * (1 - f * s);
|
||||
const t = v * (1 - (1 - f) * s);
|
||||
const mod = i % 6;
|
||||
const r = [v, q, p, p, t, v][mod];
|
||||
const g = [t, v, v, q, p, p][mod];
|
||||
const b = [p, p, t, v, v, q][mod];
|
||||
return {
|
||||
r: Math.round(r * 255),
|
||||
g: Math.round(g * 255),
|
||||
b: Math.round(b * 255),
|
||||
a: 1
|
||||
};
|
||||
},
|
||||
bound01(value, max) {
|
||||
if (this.isOnePointZero(value)) value = '100%';
|
||||
const processPercent = this.isPercentage(value);
|
||||
value = Math.min(max, Math.max(0, parseFloat(value)));
|
||||
if (processPercent) {
|
||||
value = parseInt(value * max, 10) / 100;
|
||||
}
|
||||
if ((Math.abs(value - max) < 0.000001)) {
|
||||
return 1;
|
||||
}
|
||||
return (value % max) / parseFloat(max);
|
||||
},
|
||||
isPercentage(n) {
|
||||
return typeof n === 'string' && n.indexOf('%') !== -1;
|
||||
},
|
||||
isOnePointZero(n) {
|
||||
return typeof n === 'string' && n.indexOf('.') !== -1 && parseFloat(n) === 1;
|
||||
},
|
||||
rgb2hsl(r, g, b) {
|
||||
r = r / 255;
|
||||
g = g / 255;
|
||||
b = b / 255;
|
||||
var min = Math.min(r, g, b);
|
||||
var max = Math.max(r, g, b);
|
||||
var l = (min + max) / 2;
|
||||
var difference = max - min;
|
||||
var h, s, l;
|
||||
if (max == min) {
|
||||
h = 0;
|
||||
s = 0;
|
||||
} else {
|
||||
s = l > 0.5 ? difference / (2.0 - max - min) : difference / (max + min);
|
||||
switch (max) {
|
||||
case r:
|
||||
h = (g - b) / difference + (g < b ? 6 : 0);
|
||||
break;
|
||||
case g:
|
||||
h = 2.0 + (b - r) / difference;
|
||||
break;
|
||||
case b:
|
||||
h = 4.0 + (r - g) / difference;
|
||||
break;
|
||||
}
|
||||
h = Math.round(h * 60);
|
||||
}
|
||||
s = Math.round(s * 100); //转换成百分比的形式
|
||||
l = Math.round(l * 100);
|
||||
|
||||
return {
|
||||
h: h,
|
||||
s: s + '%',
|
||||
l: l + '%'
|
||||
};
|
||||
},
|
||||
rgb2hsv(r, g, b) {
|
||||
r = this.bound01(r, 255);
|
||||
g = this.bound01(g, 255);
|
||||
b = this.bound01(b, 255);
|
||||
const max = Math.max(r, g, b);
|
||||
const min = Math.min(r, g, b);
|
||||
let h, s;
|
||||
let v = max;
|
||||
const d = max - min;
|
||||
s = max === 0 ? 0 : d / max;
|
||||
if (max === min) {
|
||||
h = 0; // achromatic
|
||||
} else {
|
||||
switch (max) {
|
||||
case r:
|
||||
h = (g - b) / d + (g < b ? 6 : 0);
|
||||
break;
|
||||
case g:
|
||||
h = (b - r) / d + 2;
|
||||
break;
|
||||
case b:
|
||||
h = (r - g) / d + 4;
|
||||
break;
|
||||
}
|
||||
h /= 6;
|
||||
}
|
||||
return {
|
||||
h: parseInt(h * 360),
|
||||
s: parseInt(s * 100),
|
||||
v: parseInt(v * 100)
|
||||
};
|
||||
},
|
||||
/**
|
||||
* rgb 转 二进制 hex
|
||||
* @param {Object} rgb
|
||||
*/
|
||||
rgbToHex(rgb) {
|
||||
let hex = [rgb.r.toString(16), rgb.g.toString(16), rgb.b.toString(16)];
|
||||
hex.map(function(str, i) {
|
||||
if (str.length == 1) {
|
||||
hex[i] = '0' + str;
|
||||
}
|
||||
});
|
||||
return hex.join('');
|
||||
},
|
||||
hex2rgba(color) {
|
||||
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
|
||||
var sColor = color.toLowerCase();
|
||||
let rgbaObj = {}
|
||||
let rgba = 'rgba'
|
||||
let k = ['r', 'g', 'b']
|
||||
if (sColor && reg.test(sColor)) {
|
||||
if (sColor.length === 4) {
|
||||
var sColorNew = "#";
|
||||
for (var i = 1; i < 4; i += 1) {
|
||||
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
|
||||
}
|
||||
sColor = sColorNew;
|
||||
}
|
||||
//处理六位的颜色值
|
||||
var sColorChange = [];
|
||||
for (var i = 1; i < 7; i += 2) {
|
||||
sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
|
||||
}
|
||||
sColorChange.push(1)
|
||||
sColorChange.forEach((o, i) => {
|
||||
if (k[i]) {
|
||||
rgbaObj[k[i]] = o
|
||||
}
|
||||
})
|
||||
return rgbaObj
|
||||
} else {
|
||||
return sColor;
|
||||
}
|
||||
},
|
||||
hsv2rgb(h, s, v) {
|
||||
h = this.bound01(h, 360) * 6;
|
||||
s = this.bound01(s, 100);
|
||||
v = this.bound01(v, 100);
|
||||
|
||||
const i = Math.floor(h);
|
||||
const f = h - i;
|
||||
const p = v * (1 - s);
|
||||
const q = v * (1 - f * s);
|
||||
const t = v * (1 - (1 - f) * s);
|
||||
const mod = i % 6;
|
||||
const r = [v, q, p, p, t, v][mod];
|
||||
const g = [t, v, v, q, p, p][mod];
|
||||
const b = [p, p, t, v, v, q][mod];
|
||||
|
||||
return {
|
||||
r: Math.round(r * 255),
|
||||
g: Math.round(g * 255),
|
||||
b: Math.round(b * 255),
|
||||
a: 1
|
||||
};
|
||||
},
|
||||
hsl2rgb(h, s, l) {
|
||||
h = h / 360;
|
||||
s = s / 100;
|
||||
l = l / 100;
|
||||
let rgb = [];
|
||||
let rgbList = ['r', 'g', 'b'];
|
||||
let rgbObj = {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 1
|
||||
}
|
||||
if (s == 0) {
|
||||
rgb = [Math.round(l * 255), Math.round(l * 255), Math.round(l * 255)];
|
||||
} else {
|
||||
var q = l >= 0.5 ? (l + s - l * s) : (l * (1 + s));
|
||||
var p = 2 * l - q;
|
||||
var tr = rgb[0] = h + 1 / 3;
|
||||
var tg = rgb[1] = h;
|
||||
var tb = rgb[2] = h - 1 / 3;
|
||||
for (var i = 0; i < rgb.length; i++) {
|
||||
var tc = rgb[i];
|
||||
if (tc < 0) {
|
||||
tc = tc + 1;
|
||||
} else if (tc > 1) {
|
||||
tc = tc - 1;
|
||||
}
|
||||
switch (true) {
|
||||
case (tc < (1 / 6)):
|
||||
tc = p + (q - p) * 6 * tc;
|
||||
break;
|
||||
case ((1 / 6) <= tc && tc < 0.5):
|
||||
tc = q;
|
||||
break;
|
||||
case (0.5 <= tc && tc < (2 / 3)):
|
||||
tc = p + (q - p) * (4 - 6 * tc);
|
||||
break;
|
||||
default:
|
||||
tc = p;
|
||||
break;
|
||||
}
|
||||
rgb[i] = Math.round(tc * 255);
|
||||
rgbObj[rgbList[i]] = rgb[i]
|
||||
}
|
||||
}
|
||||
return rgbObj;
|
||||
},
|
||||
rgbToHsb(rgb) {
|
||||
let hsb = {
|
||||
h: 0,
|
||||
s: 0,
|
||||
b: 0
|
||||
};
|
||||
let min = Math.min(rgb.r, rgb.g, rgb.b);
|
||||
let max = Math.max(rgb.r, rgb.g, rgb.b);
|
||||
let delta = max - min;
|
||||
hsb.b = max;
|
||||
hsb.s = max != 0 ? 255 * delta / max : 0;
|
||||
if (hsb.s != 0) {
|
||||
if (rgb.r == max) hsb.h = (rgb.g - rgb.b) / delta;
|
||||
else if (rgb.g == max) hsb.h = 2 + (rgb.b - rgb.r) / delta;
|
||||
else hsb.h = 4 + (rgb.r - rgb.g) / delta;
|
||||
} else hsb.h = -1;
|
||||
hsb.h *= 60;
|
||||
if (hsb.h < 0) hsb.h = 0;
|
||||
hsb.s *= 100 / 255;
|
||||
hsb.b *= 100 / 255;
|
||||
return hsb;
|
||||
},
|
||||
/**
|
||||
* hsb 转 rgb
|
||||
* @param {Object} 颜色模式 H(hues)表示色相,S(saturation)表示饱和度,B(brightness)表示亮度
|
||||
*/
|
||||
HSBToRGB(hsb) {
|
||||
let rgb = {};
|
||||
let h = Math.round(hsb.h);
|
||||
let s = Math.round((hsb.s * 255) / 100);
|
||||
let v = Math.round((hsb.b * 255) / 100);
|
||||
if (s == 0) {
|
||||
rgb.r = rgb.g = rgb.b = v;
|
||||
} else {
|
||||
let t1 = v;
|
||||
let t2 = ((255 - s) * v) / 255;
|
||||
let t3 = ((t1 - t2) * (h % 60)) / 60;
|
||||
if (h == 360) h = 0;
|
||||
if (h < 60) {
|
||||
rgb.r = t1;
|
||||
rgb.b = t2;
|
||||
rgb.g = t2 + t3;
|
||||
} else if (h < 120) {
|
||||
rgb.g = t1;
|
||||
rgb.b = t2;
|
||||
rgb.r = t1 - t3;
|
||||
} else if (h < 180) {
|
||||
rgb.g = t1;
|
||||
rgb.r = t2;
|
||||
rgb.b = t2 + t3;
|
||||
} else if (h < 240) {
|
||||
rgb.b = t1;
|
||||
rgb.r = t2;
|
||||
rgb.g = t1 - t3;
|
||||
} else if (h < 300) {
|
||||
rgb.b = t1;
|
||||
rgb.g = t2;
|
||||
rgb.r = t2 + t3;
|
||||
} else if (h < 360) {
|
||||
rgb.r = t1;
|
||||
rgb.g = t2;
|
||||
rgb.b = t1 - t3;
|
||||
} else {
|
||||
rgb.r = 0;
|
||||
rgb.g = 0;
|
||||
rgb.b = 0;
|
||||
}
|
||||
}
|
||||
return {
|
||||
r: Math.round(rgb.r),
|
||||
g: Math.round(rgb.g),
|
||||
b: Math.round(rgb.b)
|
||||
};
|
||||
},
|
||||
}
|
||||
export default conversion
|
||||
201
libs/file.js
Normal file
201
libs/file.js
Normal file
@@ -0,0 +1,201 @@
|
||||
function getLocalFilePath(path) {
|
||||
if (path.indexOf('_www') === 0 || path.indexOf('_doc') === 0 || path.indexOf('_documents') === 0 || path.indexOf(
|
||||
'_downloads') === 0) {
|
||||
return path
|
||||
}
|
||||
if (path.indexOf('file://') === 0) {
|
||||
return path
|
||||
}
|
||||
if (path.indexOf('/storage/emulated/0/') === 0) {
|
||||
return path
|
||||
}
|
||||
if (path.indexOf('/') === 0) {
|
||||
var localFilePath = plus.io.convertAbsoluteFileSystem(path)
|
||||
if (localFilePath !== path) {
|
||||
return localFilePath
|
||||
} else {
|
||||
path = path.substr(1)
|
||||
}
|
||||
}
|
||||
return '_www/' + path
|
||||
}
|
||||
|
||||
function dataUrlToBase64(str) {
|
||||
var array = str.split(',')
|
||||
return array[array.length - 1]
|
||||
}
|
||||
|
||||
var index = 0
|
||||
|
||||
function getNewFileId() {
|
||||
return Date.now() + String(index++)
|
||||
}
|
||||
|
||||
function biggerThan(v1, v2) {
|
||||
var v1Array = v1.split('.')
|
||||
var v2Array = v2.split('.')
|
||||
var update = false
|
||||
for (var index = 0; index < v2Array.length; index++) {
|
||||
var diff = v1Array[index] - v2Array[index]
|
||||
if (diff !== 0) {
|
||||
update = diff > 0
|
||||
break
|
||||
}
|
||||
}
|
||||
return update
|
||||
}
|
||||
|
||||
export function pathToBase64(path) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (typeof window === 'object' && 'document' in window) {
|
||||
if (typeof FileReader === 'function') {
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.open('GET', path, true)
|
||||
xhr.responseType = 'blob'
|
||||
xhr.onload = function() {
|
||||
if (this.status === 200) {
|
||||
let fileReader = new FileReader()
|
||||
fileReader.onload = function(e) {
|
||||
resolve(e.target.result)
|
||||
}
|
||||
fileReader.onerror = reject
|
||||
fileReader.readAsDataURL(this.response)
|
||||
}
|
||||
}
|
||||
xhr.onerror = reject
|
||||
xhr.send()
|
||||
return
|
||||
}
|
||||
var canvas = document.createElement('canvas')
|
||||
var c2x = canvas.getContext('2d')
|
||||
var img = new Image
|
||||
img.onload = function() {
|
||||
canvas.width = img.width
|
||||
canvas.height = img.height
|
||||
c2x.drawImage(img, 0, 0)
|
||||
resolve(canvas.toDataURL())
|
||||
canvas.height = canvas.width = 0
|
||||
}
|
||||
img.onerror = reject
|
||||
img.src = path
|
||||
return
|
||||
}
|
||||
if (typeof plus === 'object') {
|
||||
plus.io.resolveLocalFileSystemURL(getLocalFilePath(path), function(entry) {
|
||||
entry.file(function(file) {
|
||||
var fileReader = new plus.io.FileReader()
|
||||
fileReader.onload = function(data) {
|
||||
resolve(data.target.result)
|
||||
}
|
||||
fileReader.onerror = function(error) {
|
||||
reject(error)
|
||||
}
|
||||
fileReader.readAsDataURL(file)
|
||||
}, function(error) {
|
||||
reject(error)
|
||||
})
|
||||
}, function(error) {
|
||||
reject(error)
|
||||
})
|
||||
return
|
||||
}
|
||||
if (typeof wx === 'object' && wx.canIUse('getFileSystemManager')) {
|
||||
wx.getFileSystemManager().readFile({
|
||||
filePath: path,
|
||||
encoding: 'base64',
|
||||
success: function(res) {
|
||||
resolve('data:image/png;base64,' + res.data)
|
||||
},
|
||||
fail: function(error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
reject(new Error('not support'))
|
||||
})
|
||||
}
|
||||
|
||||
export function base64ToPath(base64) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (typeof window === 'object' && 'document' in window) {
|
||||
base64 = base64.split(',')
|
||||
var type = base64[0].match(/:(.*?);/)[1]
|
||||
var str = atob(base64[1])
|
||||
var n = str.length
|
||||
var array = new Uint8Array(n)
|
||||
while (n--) {
|
||||
array[n] = str.charCodeAt(n)
|
||||
}
|
||||
return resolve((window.URL || window.webkitURL).createObjectURL(new Blob([array], {
|
||||
type: type
|
||||
})))
|
||||
}
|
||||
var extName = base64.split(',')[0].match(/data\:\S+\/(\S+);/)
|
||||
if (extName) {
|
||||
extName = extName[1]
|
||||
} else {
|
||||
reject(new Error('base64 error'))
|
||||
}
|
||||
var fileName = getNewFileId() + '.' + extName
|
||||
if (typeof plus === 'object') {
|
||||
var basePath = '_doc'
|
||||
var dirPath = 'uniapp_temp'
|
||||
var filePath = basePath + '/' + dirPath + '/' + fileName
|
||||
if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime
|
||||
.innerVersion)) {
|
||||
plus.io.resolveLocalFileSystemURL(basePath, function(entry) {
|
||||
entry.getDirectory(dirPath, {
|
||||
create: true,
|
||||
exclusive: false,
|
||||
}, function(entry) {
|
||||
entry.getFile(fileName, {
|
||||
create: true,
|
||||
exclusive: false,
|
||||
}, function(entry) {
|
||||
entry.createWriter(function(writer) {
|
||||
writer.onwrite = function() {
|
||||
resolve(filePath)
|
||||
}
|
||||
writer.onerror = reject
|
||||
writer.seek(0)
|
||||
writer.writeAsBinary(dataUrlToBase64(base64))
|
||||
}, reject)
|
||||
}, reject)
|
||||
}, reject)
|
||||
}, reject)
|
||||
return
|
||||
}
|
||||
var bitmap = new plus.nativeObj.Bitmap(fileName)
|
||||
bitmap.loadBase64Data(base64, function() {
|
||||
bitmap.save(filePath, {}, function() {
|
||||
bitmap.clear()
|
||||
resolve(filePath)
|
||||
}, function(error) {
|
||||
bitmap.clear()
|
||||
reject(error)
|
||||
})
|
||||
}, function(error) {
|
||||
bitmap.clear()
|
||||
reject(error)
|
||||
})
|
||||
return
|
||||
}
|
||||
if (typeof wx === 'object' && wx.canIUse('getFileSystemManager')) {
|
||||
var filePath = wx.env.USER_DATA_PATH + '/' + fileName
|
||||
wx.getFileSystemManager().writeFile({
|
||||
filePath: filePath,
|
||||
data: dataUrlToBase64(base64),
|
||||
encoding: 'base64',
|
||||
success: function() {
|
||||
resolve(filePath)
|
||||
},
|
||||
fail: function(error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
reject(new Error('not support'))
|
||||
})
|
||||
}
|
||||
148
libs/permission.js
Normal file
148
libs/permission.js
Normal file
@@ -0,0 +1,148 @@
|
||||
import {
|
||||
i18n
|
||||
} from '../locale/setupI18n';
|
||||
|
||||
let permission = {
|
||||
permissionList: uni.getStorageSync('permissionList') || [],
|
||||
hasP(enCode, menuIds) {
|
||||
if (!menuIds) return false
|
||||
const list = permission.permissionList.filter(o => o.modelId === menuIds)
|
||||
if (!list.length) return false
|
||||
const columnList = list[0] && list[0].column ? list[0].column : []
|
||||
if (!columnList.length) return false
|
||||
const hasPermission = columnList.some(column => column.enCode === enCode)
|
||||
if (hasPermission) return true
|
||||
return false
|
||||
},
|
||||
hasFormP(enCode, menuIds) {
|
||||
if (!menuIds) return false
|
||||
const list = permission.permissionList.filter(o => o.modelId === menuIds)
|
||||
if (!list.length) return false
|
||||
const formList = list[0] && list[0].form ? list[0].form : []
|
||||
if (!formList.length) return false
|
||||
const hasPermission = formList.some(form => form.enCode === enCode)
|
||||
if (hasPermission) return true
|
||||
return false
|
||||
},
|
||||
hasBtnP(enCode, menuIds) {
|
||||
if (!menuIds) return false
|
||||
const list = permission.permissionList.filter(o => o.modelId === menuIds)
|
||||
if (!list.length) return false
|
||||
const btnList = list[0] && list[0].button ? list[0].button : []
|
||||
if (!btnList.length) return false
|
||||
const hasPermission = btnList.some(btn => btn.enCode === enCode)
|
||||
if (hasPermission) return true
|
||||
return false
|
||||
},
|
||||
getPermission(columnData, menuId, getScriptFunc) {
|
||||
let btnsList = columnData.btnsList
|
||||
let customBtnsList = columnData.customBtnsList
|
||||
let columnBtnsList = columnData.columnBtnsList.filter(o => o.show)
|
||||
const useBtnPermission = columnData.useBtnPermission
|
||||
const useColumnPermission = columnData.useColumnPermission
|
||||
const useFormPermission = columnData.useFormPermission
|
||||
const useBtnPermissionList = [...btnsList, ...columnBtnsList]
|
||||
let btnPermission = [];
|
||||
let customBtnsPermission = [];
|
||||
let columnPermission = [];
|
||||
let formList = [];
|
||||
let currentMenu = {}
|
||||
let btn_list = ['detail', 'edit', 'add', 'remove', 'batchRemove']
|
||||
let labelS = {}
|
||||
let enableFunc = {}
|
||||
useBtnPermissionList.map((o) => {
|
||||
if (btn_list.includes(o.value) && o.show) {
|
||||
labelS['btn_' + o.value] = o.labelI18nCode ? i18n.global.t(o.labelI18nCode, o.label) : o
|
||||
.label
|
||||
}
|
||||
})
|
||||
let isMenu = permission.permissionList.filter((o) => {
|
||||
if (o.modelId === menuId) return currentMenu = o
|
||||
})
|
||||
//按钮
|
||||
if (useBtnPermission) {
|
||||
if (customBtnsList && customBtnsList.length) {
|
||||
for (let i = 0; i < customBtnsList.length; i++) {
|
||||
inner: for (let j = 0; j < currentMenu.button.length; j++) {
|
||||
if (customBtnsList[i].value === currentMenu.button[j].enCode) {
|
||||
customBtnsPermission.push(customBtnsList[i])
|
||||
break inner
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!!isMenu.length) {
|
||||
for (let i = 0; i < useBtnPermissionList.length; i++) {
|
||||
inner: for (let j = 0; j < currentMenu.button.length; j++) {
|
||||
if ('btn_' + useBtnPermissionList[i].value === currentMenu.button[j].enCode) {
|
||||
btnPermission.push(currentMenu.button[j].enCode)
|
||||
break inner
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < useBtnPermissionList.length; i++) {
|
||||
inner: for (let j = 0; j < btn_list.length; j++) {
|
||||
if (useBtnPermissionList[i].show && useBtnPermissionList[i].value === btn_list[j]) {
|
||||
btnPermission.push('btn_' + useBtnPermissionList[i].value)
|
||||
break inner
|
||||
}
|
||||
}
|
||||
}
|
||||
customBtnsPermission = customBtnsList
|
||||
}
|
||||
// 启用规则
|
||||
columnBtnsList.map((o) => {
|
||||
enableFunc[o.value] = () => {
|
||||
return true
|
||||
}
|
||||
if (o.event && o.event.enableFunc) {
|
||||
const func = getScriptFunc(o.event.enableFunc)
|
||||
enableFunc[o.value] = func
|
||||
}
|
||||
})
|
||||
// 启用规则自定义
|
||||
customBtnsList.map((o) => {
|
||||
enableFunc[o.value] = () => {
|
||||
return true
|
||||
}
|
||||
if (o.event && o.event.enableFunc) {
|
||||
const func = getScriptFunc(o.event.enableFunc)
|
||||
enableFunc[o.value] = func
|
||||
}
|
||||
})
|
||||
if (useColumnPermission) {
|
||||
if (!!isMenu.length) {
|
||||
columnData.columnList.forEach((o, i) => {
|
||||
currentMenu.column.forEach((m, j) => {
|
||||
if (o.prop === m.enCode) {
|
||||
columnPermission.push(o)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
} else {
|
||||
columnPermission = columnData.columnList
|
||||
}
|
||||
|
||||
if (useFormPermission && !!isMenu.length) formList = currentMenu.form
|
||||
return {
|
||||
labelS,
|
||||
btnPermission,
|
||||
customBtnsPermission,
|
||||
columnPermission,
|
||||
formPermission: {
|
||||
formList,
|
||||
useFormPermission,
|
||||
menuId
|
||||
},
|
||||
enableFunc,
|
||||
useBtnPermission
|
||||
}
|
||||
},
|
||||
updatePermissionList() {
|
||||
permission.permissionList = uni.getStorageSync('permissionList') || []
|
||||
}
|
||||
}
|
||||
export default permission
|
||||
137
libs/resources.js
Normal file
137
libs/resources.js
Normal file
@@ -0,0 +1,137 @@
|
||||
const resources = {
|
||||
startup: {
|
||||
main: "https://app.cdn.jnpfsoft.com/image/3.2/startup@2x.png",
|
||||
},
|
||||
login: {
|
||||
banner: "https://app.cdn.jnpfsoft.com/image/3.0/login/top.png",
|
||||
logo: "https://app.cdn.jnpfsoft.com/image/banner/logo.png",
|
||||
},
|
||||
banner: {
|
||||
home1Url: "https://app.cdn.jnpfsoft.com/image/3.2/banner1.png",
|
||||
home2Url: "https://app.cdn.jnpfsoft.com/image/3.2/banner2.png",
|
||||
home3Url: "https://app.cdn.jnpfsoft.com/image/3.2/banner4.png",
|
||||
contactus: "https://app.cdn.jnpfsoft.com/image/banner/contactus.png",
|
||||
loginlogo: "https://app.cdn.jnpfsoft.com/image/banner/logo.png",
|
||||
accountSecurity: "https://app.cdn.jnpfsoft.com/image/banner/accountSecurity.png"
|
||||
},
|
||||
message: {
|
||||
nocontent: "https://app.cdn.jnpfsoft.com/image/message/nocontent.png",
|
||||
nodata: "https://app.cdn.jnpfsoft.com/image/message/nodata.png",
|
||||
},
|
||||
//引导页
|
||||
guide: {
|
||||
guide1: "https://app.cdn.jnpfsoft.com/image/v5.0/guide1.png",
|
||||
guide2: "https://app.cdn.jnpfsoft.com/image/v5.0/guide2.png",
|
||||
guide3: "https://app.cdn.jnpfsoft.com/image/v5.0/guide3.png",
|
||||
},
|
||||
extend: {
|
||||
againlocation: "https://app.cdn.jnpfsoft.com/image/extend/againlocation.png",
|
||||
file: "https://app.cdn.jnpfsoft.com/image/extend/file.png",
|
||||
location: "https://app.cdn.jnpfsoft.com/image/extend/location.png",
|
||||
location3: "https://app.cdn.jnpfsoft.com/image/extend/location%403x.png",
|
||||
pause: "https://app.cdn.jnpfsoft.com/image/extend/pause.png",
|
||||
play: "https://app.cdn.jnpfsoft.com/image/extend/play.png",
|
||||
pluse: "https://app.cdn.jnpfsoft.com/image/extend/plus.png",
|
||||
record: "https://app.cdn.jnpfsoft.com/image/extend/record.png",
|
||||
stop: "https://app.cdn.jnpfsoft.com/image/extend/stop.png",
|
||||
trash: "https://app.cdn.jnpfsoft.com/image/extend/trash.png"
|
||||
},
|
||||
common: {
|
||||
currentIcon: "https://app.cdn.jnpfsoft.com/image/common/currentIcon.png",
|
||||
defaultIcon: "https://app.cdn.jnpfsoft.com/image/common/defaultIcon.png",
|
||||
agreement: "https://app.cdn.jnpfsoft.com/image/common/agreement.png",
|
||||
wechat_qrcode: "https://app.cdn.jnpfsoft.com/image/common/wechat_qrcode.jpg",
|
||||
new_edition: "https://app.cdn.jnpfsoft.com/image/common/new_edition.png"
|
||||
},
|
||||
jnapp: "https://app.cdn.jnpfsoft.com/jnapp/20200415.apk",
|
||||
userAgreement: "https://m.yinmaisoft.com/userAgreement.html", //用户协议
|
||||
privacyPolicy: "https://m.yinmaisoft.com/privacyPolicy.html", //隐私政策
|
||||
appStore: "https://apps.apple.com/cn/app/jnapp/id1490797314",
|
||||
status: {
|
||||
//前加签
|
||||
frontSign: "https://app.cdn.jnpfsoft.com/image/flow/frontSign.png",
|
||||
//加签
|
||||
addSign: "https://app.cdn.jnpfsoft.com/image/flow/addSign.png",
|
||||
//指派
|
||||
assign: "https://app.cdn.jnpfsoft.com/image/flow/assign.png",
|
||||
//拒绝
|
||||
refuse: "https://app.cdn.jnpfsoft.com/image/flow/refuse.png",
|
||||
//等待提交
|
||||
submit: "https://app.cdn.jnpfsoft.com/image/flow/submit.png",
|
||||
//等待审核
|
||||
review: "https://app.cdn.jnpfsoft.com/image/flow/review.png",
|
||||
//已通过
|
||||
adopt: "https://app.cdn.jnpfsoft.com/image/flow/adopt.png",
|
||||
//审核通过
|
||||
reviewAdopt: "https://app.cdn.jnpfsoft.com/image/flow/reviewAdopt.png",
|
||||
//审核退回
|
||||
reviewRefuse: "https://app.cdn.jnpfsoft.com/image/flow/reviewRefuse.png",
|
||||
//流程撤回
|
||||
reviewUndo: "https://app.cdn.jnpfsoft.com/image/flow/reviewUndo.png",
|
||||
//审核终止
|
||||
reviewStop: "https://app.cdn.jnpfsoft.com/image/flow/reviewStop.png",
|
||||
//委托中
|
||||
entrusting: "https://app.cdn.jnpfsoft.com/image/flow/entrusting.png",
|
||||
//已失效
|
||||
expired: "https://app.cdn.jnpfsoft.com/image/flow/expired.png",
|
||||
//未生效
|
||||
notEffective: "https://app.cdn.jnpfsoft.com/image/flow/notEffective.png",
|
||||
//生效中
|
||||
effectuate: "https://app.cdn.jnpfsoft.com/image/flow/effectuate.png",
|
||||
//未开始
|
||||
notStarted: "https://app.cdn.jnpfsoft.com/image/flow/notStarted.png",
|
||||
//已被挂起
|
||||
suspend: "https://app.cdn.jnpfsoft.com/image/flow/suspend.png",
|
||||
//转向
|
||||
trun: "https://app.cdn.jnpfsoft.com/image/flow/trun.png",
|
||||
//已退回
|
||||
back: "https://app.cdn.jnpfsoft.com/image/flow/back.png",
|
||||
//已终止
|
||||
cancel: "https://app.cdn.jnpfsoft.com/image/flow/cancel.png",
|
||||
//进行中
|
||||
doing: "https://app.cdn.jnpfsoft.com/image/flow/doing.png",
|
||||
//待提交
|
||||
draft: "https://app.cdn.jnpfsoft.com/image/flow/draft.png",
|
||||
//已暂停
|
||||
pause: "https://app.cdn.jnpfsoft.com/image/flow/pause.png",
|
||||
//已撤回
|
||||
recall: "https://app.cdn.jnpfsoft.com/image/flow/recall.png",
|
||||
//已拒绝
|
||||
reject: "https://app.cdn.jnpfsoft.com/image/flow/reject.png",
|
||||
//已撤销
|
||||
revoke: "https://app.cdn.jnpfsoft.com/image/flow/revoke.png",
|
||||
//撤销中
|
||||
revoking: "https://app.cdn.jnpfsoft.com/image/flow/revoking.png",
|
||||
//待签收
|
||||
signfor: "https://app.cdn.jnpfsoft.com/image/flow/signfor.png",
|
||||
//流转中
|
||||
circulation: "https://app.cdn.jnpfsoft.com/image/flow/circulation.png",
|
||||
//退回
|
||||
return: "https://app.cdn.jnpfsoft.com/image/flow/return.png",
|
||||
//加签
|
||||
addSign: "https://app.cdn.jnpfsoft.com/image/flow/addSign.png",
|
||||
//同意
|
||||
agree: "https://app.cdn.jnpfsoft.com/image/flow/agree.png",
|
||||
//转审
|
||||
transfer: "https://app.cdn.jnpfsoft.com/image/flow/transfer.png",
|
||||
//转办
|
||||
transfer2: "https://app.cdn.jnpfsoft.com/image/flow/transfer2.png",
|
||||
//协办
|
||||
assist: "https://app.cdn.jnpfsoft.com/image/flow/assist.png"
|
||||
},
|
||||
document: {
|
||||
wordImg: 'https://app.cdn.jnpfsoft.com/image/document/word.png',
|
||||
excelImg: 'https://app.cdn.jnpfsoft.com/image/document/excel.png',
|
||||
pptImg: 'https://app.cdn.jnpfsoft.com/image/document/ppt.png',
|
||||
pdfImg: 'https://app.cdn.jnpfsoft.com/image/document/pdf.png',
|
||||
rarImg: 'https://app.cdn.jnpfsoft.com/image/document/rar.png',
|
||||
txtImg: 'https://app.cdn.jnpfsoft.com/image/document/txt.png',
|
||||
codeImg: 'https://app.cdn.jnpfsoft.com/image/document/code.png',
|
||||
imageImg: 'https://app.cdn.jnpfsoft.com/image/document/image.png',
|
||||
audioImg: 'https://app.cdn.jnpfsoft.com/image/document/audio.png',
|
||||
blankImg: 'https://app.cdn.jnpfsoft.com/image/document/blank.png',
|
||||
folderImg: 'https://app.cdn.jnpfsoft.com/image/document/folder.png',
|
||||
}
|
||||
}
|
||||
|
||||
export default resources
|
||||
Reference in New Issue
Block a user