2022-06-10 16:14:13 +08:00
|
|
|
|
import http from "./http";
|
|
|
|
|
|
import Vue from "vue";
|
2022-06-13 17:52:26 +08:00
|
|
|
|
import CryptoJS from "./crypto-js";
|
2022-06-10 16:14:13 +08:00
|
|
|
|
|
2022-06-10 16:46:03 +08:00
|
|
|
|
/**
|
2022-06-13 17:21:40 +08:00
|
|
|
|
* 登录方法
|
2022-06-10 16:46:03 +08:00
|
|
|
|
*/
|
2022-06-13 17:21:40 +08:00
|
|
|
|
export const config = {
|
2022-06-10 16:14:13 +08:00
|
|
|
|
state: () => ({}),
|
|
|
|
|
|
mutations: {
|
2022-06-13 17:21:40 +08:00
|
|
|
|
getConfig(state, params) {
|
|
|
|
|
|
for (const key in params) {
|
2022-06-13 19:47:49 +08:00
|
|
|
|
Vue.set(state, key, params[key])
|
2022-06-10 16:14:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
actions: {
|
2022-06-13 17:21:40 +08:00
|
|
|
|
agentSign({state, commit}, params) {
|
|
|
|
|
|
//授权jssdk在url上使用,并获取corpId
|
|
|
|
|
|
let url = window.location.href
|
|
|
|
|
|
if (state.agentSignURL == url) {
|
|
|
|
|
|
return Promise.resolve()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
commit("getConfig", {agentSignURL: url})
|
|
|
|
|
|
let action = "/app/wxcp/portal/agentSign"
|
2022-06-13 18:25:23 +08:00
|
|
|
|
if (!!params?.action) {
|
2022-06-13 17:21:40 +08:00
|
|
|
|
action = params.action
|
|
|
|
|
|
delete params.action
|
2022-06-16 18:23:29 +08:00
|
|
|
|
} else if (!!params?.suiteId) {
|
2022-06-15 15:10:59 +08:00
|
|
|
|
action = "/app/wxcptp/portal/agentSign"
|
2022-06-10 16:14:13 +08:00
|
|
|
|
}
|
2022-06-13 17:21:40 +08:00
|
|
|
|
return http.post(action, null, {
|
|
|
|
|
|
withoutToken: true,
|
|
|
|
|
|
params: {...params, url}
|
|
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res?.data) {
|
|
|
|
|
|
let config = {
|
|
|
|
|
|
...params,
|
|
|
|
|
|
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
|
|
|
beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
|
|
|
|
|
corpid: res.data.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
|
|
|
|
|
|
agentid: res.data.agentId, // 必填,企业微信的应用id (e.g. 1000247)
|
|
|
|
|
|
timestamp: Number(res.data.timestamp), // 必填,生成签名的时间戳
|
|
|
|
|
|
nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
|
|
|
|
|
|
signature: res.data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
|
|
|
|
|
|
...res.data,
|
|
|
|
|
|
agentSignURL: url
|
|
|
|
|
|
}
|
|
|
|
|
|
commit("getConfig", config)
|
|
|
|
|
|
return config
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
|
console.error(err)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
getCode({state, dispatch}, tryAgentSign = false) {
|
2022-06-22 10:16:04 +08:00
|
|
|
|
let {corpid: corpId, suiteId, agentid: agentId} = state, url = location.href, REDIRECT_URI = encodeURIComponent(url), scope = "snsapi_privateinfo"
|
2022-06-13 17:21:40 +08:00
|
|
|
|
if (/\/AppForm\//.test(location.search)) {
|
2022-07-15 17:56:15 +08:00
|
|
|
|
scope = "snsapi_base"
|
2022-06-13 22:27:25 +08:00
|
|
|
|
} else if (suiteId) {
|
|
|
|
|
|
corpId = suiteId
|
|
|
|
|
|
scope = "snsapi_privateinfo"
|
2022-06-13 17:21:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
if (corpId && scope) {
|
2022-06-22 10:16:04 +08:00
|
|
|
|
let oauthURL = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&agentid=AGENTID#wechat_redirect'
|
2022-06-13 19:47:49 +08:00
|
|
|
|
.replace(/APPID/g, corpId)
|
2022-06-13 17:21:40 +08:00
|
|
|
|
.replace(/REDIRECT_URI/g, REDIRECT_URI)
|
2022-06-13 19:47:49 +08:00
|
|
|
|
.replace(/SCOPE/g, scope)
|
2022-06-22 10:16:04 +08:00
|
|
|
|
.replace(/AGENTID/g, agentId)
|
2022-07-19 15:49:46 +08:00
|
|
|
|
console.log(oauthURL)
|
2022-06-13 19:47:49 +08:00
|
|
|
|
location.replace(oauthURL)
|
2022-06-13 17:21:40 +08:00
|
|
|
|
} else if (!tryAgentSign) {
|
2022-06-15 15:10:59 +08:00
|
|
|
|
dispatch("agentSign", {corpId, suiteId}).then(() => dispatch("getCode", true)).then(() => resolve())
|
2022-06-13 17:21:40 +08:00
|
|
|
|
} else reject("URL缺少必要参数(corpId)")
|
2022-06-10 16:14:13 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
2022-06-13 17:21:40 +08:00
|
|
|
|
getToken({state, commit, dispatch}, params) {
|
|
|
|
|
|
const encryptByDES = password => {
|
|
|
|
|
|
let isIos = uni.getSystemInfoSync().system.toUpperCase == 'ios'
|
|
|
|
|
|
let key = "thanks,villcloud"
|
|
|
|
|
|
let iv = CryptoJS.enc.Latin1.parse(key)
|
|
|
|
|
|
let encrypted = CryptoJS.AES.encrypt(password, iv, {
|
|
|
|
|
|
iv: iv,
|
|
|
|
|
|
mode: CryptoJS.mode.CBC,
|
|
|
|
|
|
padding: CryptoJS.pad.ZeroPadding
|
|
|
|
|
|
})
|
|
|
|
|
|
if (isIos) {
|
|
|
|
|
|
return encodeURIComponent(encrypted.toString());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return encrypted.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-06-13 20:54:05 +08:00
|
|
|
|
let {module, code} = params, action = "/auth/oauth/token"
|
|
|
|
|
|
if (!!code) {
|
|
|
|
|
|
action = "/auth/wechatcp/token"
|
|
|
|
|
|
}
|
|
|
|
|
|
return http.post(action, params, {
|
2022-06-13 17:21:40 +08:00
|
|
|
|
withoutToken: true,
|
|
|
|
|
|
module,
|
|
|
|
|
|
params: {
|
|
|
|
|
|
...params, grant_type: 'password',
|
|
|
|
|
|
password: encryptByDES(params.password)
|
|
|
|
|
|
},
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Authorization: "Basic d2VjaGF0OndlY2hhdA=="
|
2022-06-10 16:14:13 +08:00
|
|
|
|
}
|
2022-06-13 17:21:40 +08:00
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res?.access_token) {
|
|
|
|
|
|
return [res?.token_type, res?.access_token].join(" ").trim()
|
2022-06-13 19:47:49 +08:00
|
|
|
|
} else return Promise.reject(res.msg)
|
2022-06-10 16:14:13 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
2022-06-13 17:21:40 +08:00
|
|
|
|
* 用户登录信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const user = {
|
|
|
|
|
|
state: () => ({}),
|
2022-06-10 16:14:13 +08:00
|
|
|
|
mutations: {
|
2022-06-13 17:21:40 +08:00
|
|
|
|
setUser(state, user) {
|
|
|
|
|
|
for (const key in user) {
|
|
|
|
|
|
Vue.set(state, key, user[key])
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-06-10 16:14:13 +08:00
|
|
|
|
initWaterMarker(state) {
|
|
|
|
|
|
const waterMarked = document.querySelector('#waterMarker')
|
2022-06-13 17:21:40 +08:00
|
|
|
|
if (!waterMarked && state?.name) {
|
2022-06-10 16:14:13 +08:00
|
|
|
|
const waterMarker = document.createElement('div')
|
|
|
|
|
|
waterMarker.id = 'waterMarker'
|
|
|
|
|
|
waterMarker.style.position = 'absolute'
|
|
|
|
|
|
waterMarker.style.display = 'flex'
|
|
|
|
|
|
waterMarker.style.flexWrap = 'wrap'
|
|
|
|
|
|
waterMarker.style.overflow = 'hidden'
|
|
|
|
|
|
waterMarker.style.justifyContent = 'space-between'
|
|
|
|
|
|
waterMarker.style.alignContent = 'flex-start'
|
|
|
|
|
|
waterMarker.style.zIndex = '2'
|
|
|
|
|
|
waterMarker.style.top = '0'
|
|
|
|
|
|
waterMarker.style.color = 'rgba(153,153,153,.2)'
|
|
|
|
|
|
waterMarker.style.width = '100%'
|
|
|
|
|
|
waterMarker.style.height = '100%'
|
|
|
|
|
|
waterMarker.style.pointerEvents = 'none'
|
|
|
|
|
|
for (let i = 0; i < 200; i++) {
|
|
|
|
|
|
const markerItem = document.createElement('div')
|
|
|
|
|
|
markerItem.style.fontSize = '14px'
|
|
|
|
|
|
markerItem.style.padding = '30px'
|
|
|
|
|
|
markerItem.style.height = '80px'
|
|
|
|
|
|
markerItem.style.transform = 'rotate(-20deg)'
|
|
|
|
|
|
markerItem.style.flexShrink = '0'
|
2022-06-13 17:21:40 +08:00
|
|
|
|
markerItem.innerText = state?.name + state?.phone?.slice(-4) || "未授权"
|
2022-06-10 16:14:13 +08:00
|
|
|
|
waterMarker.appendChild(markerItem)
|
|
|
|
|
|
}
|
|
|
|
|
|
document.querySelector('uni-page-body')?.appendChild(waterMarker)
|
|
|
|
|
|
}
|
|
|
|
|
|
// canvas 方案
|
|
|
|
|
|
// const HiDPICanvas = (w, h, ratio) => {
|
|
|
|
|
|
// const PIXEL_RATIO = () => {
|
|
|
|
|
|
// const c = document.createElement("canvas"),
|
|
|
|
|
|
// ctx = c.getContext("2d"),
|
|
|
|
|
|
// dpr = window.devicePixelRatio || 1,
|
|
|
|
|
|
// bsr = ctx['webkitBackingStorePixelRatio'] ||
|
|
|
|
|
|
// ctx['mozBackingStorePixelRatio'] ||
|
|
|
|
|
|
// ctx['msBackingStorePixelRatio'] ||
|
|
|
|
|
|
// ctx['oBackingStorePixelRatio'] ||
|
|
|
|
|
|
// ctx['backingStorePixelRatio'] || 1;
|
|
|
|
|
|
//
|
|
|
|
|
|
// return dpr / bsr;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (!ratio) {
|
|
|
|
|
|
// ratio = PIXEL_RATIO();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// const can = document.createElement("canvas");
|
|
|
|
|
|
// can.width = w * ratio;
|
|
|
|
|
|
// can.height = h * ratio;
|
|
|
|
|
|
// can.style.width = w + "px";
|
|
|
|
|
|
// can.style.height = h + "px";
|
|
|
|
|
|
// can.getContext("2d").setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
|
|
|
|
// return can
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (!waterMarked && state.user?.name) {
|
|
|
|
|
|
// const canvas = HiDPICanvas(100, 40)
|
|
|
|
|
|
// canvas.style.display = 'none';
|
|
|
|
|
|
// let ctx = canvas.getContext("2d")
|
|
|
|
|
|
// ctx.rotate(-20 * Math.PI / 180);
|
|
|
|
|
|
// ctx.fillStyle = 'rgba(153,153,153,.3)';
|
|
|
|
|
|
// ctx.textAlign = 'left';
|
|
|
|
|
|
// ctx.textBaseline = 'middle';
|
|
|
|
|
|
// ctx.font = "lighter 7px 'Microsoft YaHei UI',sans-serif"
|
|
|
|
|
|
// ctx.fillText(state.user?.name + state.user?.phone?.slice(-4) || "未授权", 0, 30);
|
|
|
|
|
|
// const waterMarker = document.createElement('div')
|
|
|
|
|
|
// if (waterMarker) {
|
|
|
|
|
|
// waterMarker.id = 'waterMarker'
|
|
|
|
|
|
// waterMarker.style.position = 'absolute'
|
|
|
|
|
|
// waterMarker.style.zIndex = '2'
|
|
|
|
|
|
// waterMarker.style.top = '0'
|
|
|
|
|
|
// waterMarker.style.width = '100%'
|
|
|
|
|
|
// waterMarker.style.height = '100%'
|
|
|
|
|
|
// waterMarker.style.pointerEvents = 'none'
|
|
|
|
|
|
// waterMarker.style.backgroundImage = "url(" + canvas.toDataURL("image/png") + ")"
|
|
|
|
|
|
// document.querySelector('uni-page-body').appendChild(waterMarker)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
2022-06-13 17:21:40 +08:00
|
|
|
|
},
|
|
|
|
|
|
actions: {
|
|
|
|
|
|
getAccount({dispatch, commit}, config) {
|
|
|
|
|
|
//获取企业微信后台账号信息
|
|
|
|
|
|
return http.post("/admin/user/detail-phone", null, config).then(res => {
|
|
|
|
|
|
if (res?.code == 0) {
|
|
|
|
|
|
commit('setUser', res.data)
|
|
|
|
|
|
return Promise.all([dispatch('getGridInfo', config)])
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
getGridInfo({commit}, config) {
|
|
|
|
|
|
//获取登录着网格员信息
|
|
|
|
|
|
return http.post("/app/appgirdmemberinfo/checkLogOnUser", null, config).then(res => {
|
|
|
|
|
|
if (res?.data) {
|
|
|
|
|
|
let {girdId, girdMemberId, girdName, checkType: girdCheckType, appGirdInfo: gridInfo} = res.data
|
|
|
|
|
|
return commit("setUser", {girdId, girdMemberId, girdName, girdCheckType, gridInfo})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2022-06-10 16:14:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-06-10 17:15:56 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 企微jssdk功能
|
|
|
|
|
|
*/
|
|
|
|
|
|
let apiList = []
|
|
|
|
|
|
export const wxwork = {
|
|
|
|
|
|
actions: {
|
2022-06-13 18:58:17 +08:00
|
|
|
|
injectJWeixin({commit, dispatch, rootState}, ops) {
|
|
|
|
|
|
const inject = (jsApiList, config = rootState.config) => new Promise((resolve, reject) => {
|
2022-06-10 17:15:56 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
let sdk = wx?.agentConfig ? wx : jWeixin
|
|
|
|
|
|
sdk?.agentConfig({
|
|
|
|
|
|
...config, jsApiList,
|
|
|
|
|
|
success: res => resolve(res),
|
|
|
|
|
|
fail: err => {
|
|
|
|
|
|
console.error(err)
|
|
|
|
|
|
reject(err)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 500)
|
|
|
|
|
|
})
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-06-15 15:10:59 +08:00
|
|
|
|
let {config: {corpId, suiteId}} = rootState
|
|
|
|
|
|
dispatch("agentSign", {corpId, suiteId}).then(config => {
|
2022-06-10 17:15:56 +08:00
|
|
|
|
if (typeof ops == "object") {
|
|
|
|
|
|
ops?.map(api => {
|
|
|
|
|
|
if (!apiList?.includes(api)) apiList.push(api)
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (!apiList?.includes(ops)) apiList.push(ops)
|
|
|
|
|
|
}
|
|
|
|
|
|
inject(apiList, config).then(r => resolve(r)).catch(err => reject(err))
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
wxInvoke(state, op) {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
let sdk = typeof wx?.invoke == 'function' ? wx : jWeixin
|
|
|
|
|
|
sdk?.invoke(op?.[0], op?.[1], op?.[2])
|
|
|
|
|
|
}, 500)
|
|
|
|
|
|
},
|
|
|
|
|
|
previewFile({dispatch}, op) {
|
|
|
|
|
|
if (window.navigator.userAgent.indexOf("Windows NT") > -1) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: "企业微信暂不支持PC端的预览文件!",
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
dispatch("injectJWeixin", "previewFile").then(() => {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
let sdk = typeof wx?.invoke == 'function' ? wx : jWeixin
|
|
|
|
|
|
sdk?.invoke('previewFile', {...op}, res => {
|
|
|
|
|
|
console.log(res)
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 500)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
closeAgent({dispatch}) {
|
|
|
|
|
|
dispatch("injectJWeixin", "closeWindow").then(() => {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
let sdk = typeof wx?.closeWindow == 'function' ? wx : jWeixin
|
|
|
|
|
|
sdk?.closeWindow()
|
|
|
|
|
|
}, 500)
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
selectEnterpriseContact({dispatch}, params) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
dispatch("injectJWeixin", "selectEnterpriseContact").then(() => {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
let sdk = typeof wx?.invoke == 'function' ? wx : jWeixin
|
|
|
|
|
|
sdk?.invoke("selectEnterpriseContact", {
|
|
|
|
|
|
fromDepartmentId: -1,
|
|
|
|
|
|
mode: "multi",
|
|
|
|
|
|
type: ["user"],
|
|
|
|
|
|
...params
|
|
|
|
|
|
}, res => {
|
|
|
|
|
|
if (res.err_msg == "selectEnterpriseContact:ok") {
|
|
|
|
|
|
if (typeof res.result == 'string') {
|
|
|
|
|
|
res.result = JSON.parse(res.result)
|
|
|
|
|
|
}
|
|
|
|
|
|
resolve(res.result)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
reject(res)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 500)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
selectPrivilegedContact({dispatch}, params) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
dispatch("injectJWeixin", "selectPrivilegedContact").then(() => {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
let sdk = typeof wx?.invoke == 'function' ? wx : jWeixin
|
|
|
|
|
|
sdk?.invoke("selectPrivilegedContact", {
|
|
|
|
|
|
fromDepartmentId: -1,
|
|
|
|
|
|
mode: "multi",
|
|
|
|
|
|
...params
|
|
|
|
|
|
}, res => {
|
|
|
|
|
|
if (res.err_msg == "selectPrivilegedContact:ok") {
|
|
|
|
|
|
if (typeof res.result == 'string') {
|
|
|
|
|
|
res.result = JSON.parse(res.result)
|
|
|
|
|
|
}
|
|
|
|
|
|
resolve(res.result)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
reject(res)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 300)
|
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
reject('error')
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|