|
|
|
import { Action, getModule, Module, Mutation, VuexModule, MutationAction } from 'vuex-module-decorators';
|
|
|
|
import { Area } from '@/pages/login/area/model';
|
|
|
|
import { Lang } from '@/i18n';
|
|
|
|
import request from '@/utils/request';
|
|
|
|
import { url } from '@/utils/url';
|
|
|
|
import { stringify } from 'query-string';
|
|
|
|
import store from '@/store';
|
|
|
|
import { page } from '@/utils/page';
|
|
|
|
//import { server } from '@/pages/login/server/model';
|
|
|
|
export interface User {
|
|
|
|
code?: string;
|
|
|
|
msg?: string;
|
|
|
|
userId?: string;
|
|
|
|
lang?: Lang;
|
|
|
|
loginName?: string;
|
|
|
|
userName?: string;
|
|
|
|
factoryCode?: string;
|
|
|
|
password?: string;
|
|
|
|
regionCode?: string;
|
|
|
|
list?: Array<Area>;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
dynamic: true,
|
|
|
|
store,
|
|
|
|
namespaced: true,
|
|
|
|
name: 'session',
|
|
|
|
})
|
|
|
|
class SessionService extends VuexModule {
|
|
|
|
/**
|
|
|
|
* 当前登录用户
|
|
|
|
*/
|
|
|
|
user: User | null = null;
|
|
|
|
Version = '';
|
|
|
|
url = '';
|
|
|
|
returnCode: any = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 当前工作区
|
|
|
|
*/
|
|
|
|
area: Area | null = null;
|
|
|
|
|
|
|
|
get isUserLoggedIn(): boolean {
|
|
|
|
return this.user !== null;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 当前工作区
|
|
|
|
*/
|
|
|
|
get password(): any {
|
|
|
|
if (this.user === null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this.user.password;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 当前用户ID
|
|
|
|
*/
|
|
|
|
get userId(): any {
|
|
|
|
if (this.user === null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this.user.userId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 当前选择语言
|
|
|
|
*/
|
|
|
|
get lang(): any {
|
|
|
|
if (this.user === null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this.user.lang;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 当前登录名
|
|
|
|
*/
|
|
|
|
get loginName(): any {
|
|
|
|
if (this.user === null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this.user.loginName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 当前工厂代码
|
|
|
|
*/
|
|
|
|
get factoryCode(): any {
|
|
|
|
if (this.user === null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this.user.factoryCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 当前区域代码
|
|
|
|
*/
|
|
|
|
get regionCode(): string | null {
|
|
|
|
if (this.area === null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this.area.regionCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 当前工作区代码
|
|
|
|
*/
|
|
|
|
get workareaCode(): string | null {
|
|
|
|
if (this.area === null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this.area.workareaCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 当前仓库代码
|
|
|
|
*/
|
|
|
|
get warehouseCode(): string | null {
|
|
|
|
if (this.area === null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this.area.warehouseCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 用户 getter
|
|
|
|
get getUser(): User {
|
|
|
|
if (this.user === null) {
|
|
|
|
throw new Error('当前无登录用户');
|
|
|
|
} else {
|
|
|
|
return this.user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 登录
|
|
|
|
@Action({ rawError: true })
|
|
|
|
async login({ username, password, lang }: { username: string; password: string; lang: Lang }): Promise<User> {
|
|
|
|
return request.post(
|
|
|
|
url.wmspda.system.login,
|
|
|
|
stringify({
|
|
|
|
userName: username,
|
|
|
|
passWord: password,
|
|
|
|
lang: lang == 'en' ? 'en_US' : 'zh_CN',
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 登出
|
|
|
|
@Mutation
|
|
|
|
logout(): void {
|
|
|
|
// logout
|
|
|
|
this.user = null;
|
|
|
|
this.area = null;
|
|
|
|
uni.reLaunch({ url: page.login.login });
|
|
|
|
}
|
|
|
|
|
|
|
|
// 保存用户信息
|
|
|
|
@Mutation
|
|
|
|
setUser(user: User): void {
|
|
|
|
this.user = user;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 保存工作区信息
|
|
|
|
@Mutation
|
|
|
|
setArea(area: Area): void {
|
|
|
|
this.area = area;
|
|
|
|
}
|
|
|
|
//查询版本号
|
|
|
|
@MutationAction
|
|
|
|
async QueryVersion(serverAddress: string) {
|
|
|
|
//const a = server.serverAddress;
|
|
|
|
//const a = ServeUrl.server.address;
|
|
|
|
console.log('serverAddress', serverAddress);
|
|
|
|
const res: any = await request.get(serverAddress + '/sgNginxDownload/Debug/setup.json');
|
|
|
|
const Version = res.version;
|
|
|
|
const url = res.url + '/' + res.file;
|
|
|
|
console.log('url..........', url);
|
|
|
|
return { Version, url };
|
|
|
|
}
|
|
|
|
//前置检测
|
|
|
|
@MutationAction
|
|
|
|
async Predetection(params: any) {
|
|
|
|
const ServeUrl = JSON.parse(uni.getStorageSync('__GWMS_APP_STATE_DATA__'));
|
|
|
|
await uni.request({
|
|
|
|
url: ServeUrl.server.address + params.url,
|
|
|
|
method: 'POST',
|
|
|
|
data: params,
|
|
|
|
success: (res: any) => {
|
|
|
|
this.returnCode = res.data.code;
|
|
|
|
console.log('returnCode', this.returnCode);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
//直接下载
|
|
|
|
// @MutationAction
|
|
|
|
// async xiazai() {
|
|
|
|
// let url: any = await request.get(this.url);
|
|
|
|
// return { url };
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
export const session = getModule(SessionService);
|