@ -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,7 +13,9 @@ 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' ,
@ -39,7 +41,7 @@ const useAuthStore = create(devtools((set, get) => ({
}
if ( perm === PERM _USE _EMAL ) {
return true //['501', '466', '599', '495', '143', '370', '639', '513', '654', '404', '383', '227'].includes(loginUser.userId)
return true //['501', '466', '599', '495', '143', '370', '639', '513', '654', '404', '383', '227'].includes(loginUser.userId)
}
// 导入邮件消息,需要配置才能使用
@ -64,10 +66,7 @@ const useAuthStore = create(devtools((set, get) => ({
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 服务器地址
@ -81,7 +80,7 @@ const useAuthStore = create(devtools((set, get) => ({
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 ,
@ -111,14 +110,14 @@ const useAuthStore = create(devtools((set, get) => ({
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
} )
@ -157,8 +156,10 @@ const useAuthStore = create(devtools((set, get) => ({
} ,
loadUserSession : ( ) => {
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"}]}'
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"}]}'
// 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"}]}`
@ -179,27 +180,23 @@ const useAuthStore = create(devtools((set, get) => ({
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 {
@ -215,11 +212,10 @@ const useAuthStore = create(devtools((set, get) => ({
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 {
@ -227,6 +223,9 @@ const useAuthStore = create(devtools((set, get) => ({
}
} )
} ,
} ) , { name : 'authStore' } ) )
} ) ,
{ name : 'authStore' } ,
) ,
)
export default useAuthStore