fix: conf

dev/full-email
Lei OT 12 months ago
parent e7ae4ea264
commit 85000e35f5

@ -3,7 +3,7 @@ import { devtools } from 'zustand/middleware'
import { fetchJSON } from '@/utils/request'
import { isEmpty, isNotEmpty } from '@/utils/commons'
import { API_HOST, BUILD_VERSION } from '@/config'
import { usingStorage } from '@/utils/usingStorage'
import { usingStorage } from '@/utils/usingStorage';
export const PERM_MERGE_CONVERSATION = 'merge-conversation'
export const PERM_ASSIGN_NEW_CONVERSATION = 'assign-new-conversation'
@ -13,9 +13,7 @@ export const PERM_IMPORT_EMAIL = 'import-email'
const WAI_SERVER_KEY = 'G-STR:WAI_SERVER'
const useAuthStore = create(
devtools(
(set, get) => ({
const useAuthStore = create(devtools((set, get) => ({
loginUser: {
userId: -1,
userIdStr: '-1',
@ -66,7 +64,10 @@ const useAuthStore = create(
setLoginStatus(200)
const json = await fetchJSON('https://p9axztuwd7x8a7.mycht.cn/dingtalk/dingtalkwork/WhatsAppAuth', { authCode })
const json = await fetchJSON(
'https://p9axztuwd7x8a7.mycht.cn/dingtalk/dingtalkwork/WhatsAppAuth',
{ authCode },
)
if (json.errcode === 0 && isNotEmpty(json.result.opisn)) {
// TODO保存个人 WhatsApp 服务器地址
@ -80,7 +81,7 @@ const useAuthStore = create(
return acc.OPI_SN
})
.join(','),
emailList: json.result?.emaillist.map((item) => {
emailList: json.result?.emaillist.map(item => {
return {
opi_sn: item.opi_sn,
mat_sn: item.mat_sn,
@ -110,14 +111,14 @@ const useAuthStore = create(
getPrimaryEmail: () => {
const { loginUser } = get()
const defaultList = loginUser.emailList.filter((email) => {
const defaultList = loginUser.emailList.filter(email => {
return email.default
})
if (defaultList.length > 0) {
return defaultList[0].email
} else {
const backupList = loginUser.emailList.filter((email) => {
const backupList = loginUser.emailList.filter(email => {
return email.backup
})
@ -156,10 +157,8 @@ const useAuthStore = create(
},
loadUserSession: () => {
let sessionData =
import.meta.env.PROD === 'production'
? window.sessionStorage.getItem('GLOBAL_SALES_LOGIN_USER')
: '{"userId":"155","userIdStr":"155","emailList":[],"whatsAppBusiness":"+8617607730395","whatsAppNo":null,"username":"尹诚诚","avatarUrl":"https://static-legacy.dingtalk.com/media/lADPBE1XYG_HAcDNAgDNAgA_512_512.jpg","mobile":"+86-18507832160","email":"ycc@hainatravel.com","openId":"K8BNXMf8ESSr1DzLVUrX7wiEiE","accountList":[{"OPI_SN":155,"OPI_Code":"YCC","OPI_NameCN":"尹诚诚","OPI_DEI_SN":1,"OPI_NameEN":"Yin Chengcheng"}]}'
let sessionData = window.sessionStorage.getItem('GLOBAL_SALES_LOGIN_USER')
// let sessionData ='{"userId":"155","userIdStr":"155","emailList":[],"whatsAppBusiness":"+8617607730395","whatsAppNo":null,"username":"尹诚诚","avatarUrl":"https://static-legacy.dingtalk.com/media/lADPBE1XYG_HAcDNAgDNAgA_512_512.jpg","mobile":"+86-18507832160","email":"ycc@hainatravel.com","openId":"K8BNXMf8ESSr1DzLVUrX7wiEiE","accountList":[{"OPI_SN":155,"OPI_Code":"YCC","OPI_NameCN":"尹诚诚","OPI_DEI_SN":1,"OPI_NameEN":"Yin Chengcheng"}]}'
// if (window.location.hostname === '202.103.68.93' && window.location.port === '4173' && isEmpty(sessionData)) {
// sessionData = `{"userId":"383","userIdStr":"383,609","emailList":[{"opi_sn":383,"mat_sn":760,"email":"lyj@asiahighlights.com","default":false,"backup":false},{"opi_sn":383,"mat_sn":759,"email":"lyj@chinahighlights.com","default":true,"backup":false},{"opi_sn":383,"mat_sn":758,"email":"lyj@hainatravel.com","default":false,"backup":false}],"username":"廖一军","avatarUrl":"https://static-legacy.dingtalk.com/media/lALPBDDrhXr716HNAoDNAoA_640_640.png","mobile":"+86-18777396951","email":"lyj@hainatravel.com","whatsAppBusiness":"8617458471254","openId":"iioljiPmZ4RPoOYpkFiSn7IKAiEiE","accountList":[{"OPI_SN":383,"OPI_Code":"LYJ","OPI_NameCN":"廖一军","OPI_DEI_SN":7,"OPI_NameEN":"Jimmy Liow"},{"OPI_SN":609,"OPI_Code":"LYJAH","OPI_NameCN":"廖一军ah","OPI_DEI_SN":28,"OPI_NameEN":"Jimmy Liow"}]}`
@ -180,23 +179,27 @@ const useAuthStore = create(
saveUserSession: () => {
const { loginUser } = get()
window.sessionStorage.setItem('GLOBAL_SALES_LOGIN_USER', JSON.stringify(loginUser))
window.sessionStorage.setItem(
'GLOBAL_SALES_LOGIN_USER',
JSON.stringify(loginUser),
)
},
setWhatsAppProfile: async (userId, whatsAppBusiness, whatsAppNo) => {
const { loginUser, saveUserSession } = get()
const postWABAUrl = `${API_HOST}/v2/set_whatsapp_info`
const params = { opi_sn: userId, whatsapp_waba: whatsAppBusiness, whatsapp_wa: whatsAppNo.replace(/\D/g, '') }
const params = {opi_sn: userId, whatsapp_waba: whatsAppBusiness, whatsapp_wa: whatsAppNo.replace(/\D/g, '')};
return fetchJSON(postWABAUrl, params).then((json) => {
return fetchJSON(postWABAUrl, params)
.then(json => {
if (json.errcode === 0) {
set(() => ({
loginUser: {
...loginUser,
whatsAppNo: whatsAppNo,
whatsAppBusiness: whatsAppBusiness,
},
}
}))
saveUserSession()
} else {
@ -212,10 +215,11 @@ const useAuthStore = create(
const params = {
groupid: 'cidFtzcIzNwNoiaGU9Q795CIg==',
msgTitle: '有人求助',
msgText: loginUser.username + '上传了销售平台' + BUILD_VERSION + '的日志',
}
msgText: loginUser.username + '上传了销售平台' + BUILD_VERSION + '的日志'
};
return fetchJSON(notifyUrl, params).then((json) => {
return fetchJSON(notifyUrl, params)
.then(json => {
if (json.errcode === 0) {
console.info('发送通知成功')
} else {
@ -223,9 +227,6 @@ const useAuthStore = create(
}
})
},
}),
{ name: 'authStore' },
),
)
}), { name: 'authStore' }))
export default useAuthStore

Loading…
Cancel
Save