|
|
|
@ -11,12 +11,20 @@ const KEY_USER_ID = 'KEY_USER_ID';
|
|
|
|
|
|
|
|
|
|
const useAuthStore = create((set, get) => ({
|
|
|
|
|
|
|
|
|
|
tokenInterval: null,
|
|
|
|
|
|
|
|
|
|
loginStatus: 0,
|
|
|
|
|
|
|
|
|
|
loginUser: {
|
|
|
|
|
userId: -1,
|
|
|
|
|
username: '',
|
|
|
|
|
avatarUrl: '',
|
|
|
|
|
mobile: '',
|
|
|
|
|
email: '',
|
|
|
|
|
token: '',
|
|
|
|
|
userId: 0, // LMI_SN
|
|
|
|
|
username: '0',
|
|
|
|
|
travelAgencyId: 0, // VEI_SN
|
|
|
|
|
travelAgencyName: '',
|
|
|
|
|
telephone: '',
|
|
|
|
|
emailAddress: '',
|
|
|
|
|
cityId: 0,
|
|
|
|
|
timeout: false,
|
|
|
|
|
permissionList: [],
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -36,15 +44,147 @@ const useAuthStore = create((set, get) => ({
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
login: async (authCode) => {
|
|
|
|
|
valdateUserPassword: async (usr, pwd) => {
|
|
|
|
|
const formData = new FormData()
|
|
|
|
|
formData.append('username', usr)
|
|
|
|
|
formData.append('Password', pwd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function fetchLoginToken() {
|
|
|
|
|
const postUrl = HT_HOST + '/service-CooperateSOA/Login'
|
|
|
|
|
const json = await postForm(postUrl, formData)
|
|
|
|
|
if (json.errcode == 0 && isNotEmpty(json.Result)) {
|
|
|
|
|
return json.Result.token;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const token = await fetchLoginToken()
|
|
|
|
|
console.info('token: ' + token)
|
|
|
|
|
|
|
|
|
|
const fetchUrl = prepareUrl(HT_HOST + '/service-CooperateSOA/GetLinkManInfo')
|
|
|
|
|
.append('token', token)
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
return fetchJSON(fetchUrl)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode == 0) {
|
|
|
|
|
set(() => ({
|
|
|
|
|
loginUser: {
|
|
|
|
|
token: token,
|
|
|
|
|
timeout: false,
|
|
|
|
|
userId: json.Result.LMI_SN,
|
|
|
|
|
username: json.Result.LoginName,
|
|
|
|
|
travelAgencyId: json.Result.LMI_VEI_SN,
|
|
|
|
|
travelAgencyName: json.Result.VName,
|
|
|
|
|
telephone: json.Result.LkPhone,
|
|
|
|
|
emailAddress: json.Result.LMI_listmail,
|
|
|
|
|
cityId: json.Result.citysn,
|
|
|
|
|
},
|
|
|
|
|
loginStatus: 302
|
|
|
|
|
}))
|
|
|
|
|
// loadPageSpy(`${json.Result.VName}-${json.Result.LoginName}`)
|
|
|
|
|
// this.startTokenInterval()
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json.errmsg + ': ' + json.errcode)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
logout: () => {
|
|
|
|
|
window.sessionStorage.clearSession()
|
|
|
|
|
set(() => ({
|
|
|
|
|
loginUser: {
|
|
|
|
|
timeout: true
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
fetchUserDetail: () => {
|
|
|
|
|
const { loginUser } = get()
|
|
|
|
|
const fetchUrl = prepareUrl(HT_HOST + '/service-CooperateSOA/GetLinkManInfo')
|
|
|
|
|
.append('token', loginUser.token)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
return fetchJSON(fetchUrl)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode == 0) {
|
|
|
|
|
set((state) => ({
|
|
|
|
|
loginUser: {
|
|
|
|
|
...state.loginUser,
|
|
|
|
|
userId: json.Result.LMI_SN,
|
|
|
|
|
username: json.Result.LoginName,
|
|
|
|
|
travelAgencyId: json.Result.LMI_VEI_SN,
|
|
|
|
|
travelAgencyName: json.Result.VName,
|
|
|
|
|
telephone: json.Result.LkPhone,
|
|
|
|
|
emailAddress: json.Result.LMI_listmail,
|
|
|
|
|
cityId: json.Result.citysn,
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
// loadPageSpy(`${json.Result.VName}-${json.Result.LoginName}`)
|
|
|
|
|
// this.startTokenInterval()
|
|
|
|
|
return loginUser
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json.errmsg + ': ' + json.errcode)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
startTokenInterval: () => {
|
|
|
|
|
const { loginUser } = get()
|
|
|
|
|
async function fetchLastRequet() {
|
|
|
|
|
const fetchUrl = prepareUrl(HT_HOST + '/service-CooperateSOA/GetLastReqDate')
|
|
|
|
|
.append('token', loginUser.token)
|
|
|
|
|
.build();
|
|
|
|
|
const json = await fetchJSON(fetchUrl)
|
|
|
|
|
if (json.errcode == 0 && isNotEmpty(json.result)) {
|
|
|
|
|
return json.result.LastReqDate;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function checkTokenTimeout() {
|
|
|
|
|
const lastRequest = await fetchLastRequet();
|
|
|
|
|
const lastReqDate = new Date(lastRequest);
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const diffTime = now.getTime() - lastReqDate.getTime();
|
|
|
|
|
const diffHours = diffTime/1000/60/60;
|
|
|
|
|
if (diffHours > 4) {
|
|
|
|
|
authStore.logout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const interval = setInterval(() => checkTokenTimeout(), 1000*60*20)
|
|
|
|
|
set(() => ({
|
|
|
|
|
tokenInterval: interval
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
changeUserPassword: (password, newPassword) => {
|
|
|
|
|
const { loginUser } = get()
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('UserID', loginUser.userId);
|
|
|
|
|
formData.append('Password', password);
|
|
|
|
|
formData.append('NewPassword', newPassword);
|
|
|
|
|
formData.append('token', loginUser.token);
|
|
|
|
|
const postUrl = HT_HOST + '/service-CooperateSOA/SetPassword';
|
|
|
|
|
|
|
|
|
|
return postForm(postUrl, formData)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode == 0) {
|
|
|
|
|
return json;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json.errmsg + ': ' + json.errcode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
class Auth {
|
|
|
|
|
export default useAuthStore
|
|
|
|
|
|
|
|
|
|
export class Auth {
|
|
|
|
|
|
|
|
|
|
constructor(root) {
|
|
|
|
|
makeAutoObservable(this, { rootStore: false });
|
|
|
|
@ -161,24 +301,6 @@ class Auth {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//供应商列表
|
|
|
|
|
fetchVendorList(){
|
|
|
|
|
const authStore = this;
|
|
|
|
|
const fetchUrl = prepareUrl(HT_HOST + '/service-cusservice/PTGetHWVendorList')
|
|
|
|
|
.append('token', authStore.login.token)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
return fetchJSON(fetchUrl)
|
|
|
|
|
.then(json => {
|
|
|
|
|
//console.log(json);
|
|
|
|
|
if (json.errcode == 0) {
|
|
|
|
|
runInAction(() => {
|
|
|
|
|
this.VendorList = json.Result;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
login = {
|
|
|
|
|
token: '',
|
|
|
|
|
userId: 0, // LMI_SN
|
|
|
|
@ -192,4 +314,4 @@ class Auth {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Auth;
|
|
|
|
|
// export Auth;
|
|
|
|
|