You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
5.9 KiB
TypeScript

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 {
access_token?: string;
userId?: string;
loginName?: string;
userName?: string;
password?: string;
poolNameList?: Array<Area>;
createBy?: string;
menuList?: Array<Menu>;
}
export interface FactoryCode {
factoryCode?: string;
poolName?: string;
}
export interface Menu {
menuName?: string;
path?: string;
perms?: string;
}
@Module({
dynamic: true,
store,
namespaced: true,
name: 'session',
})
class SessionService extends VuexModule {
/**
*
*/
user: User | null = null;
factory: FactoryCode | null = null;
factoryCode: string;
//factoryCode: factoryCode | 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 userName(): any {
if (this.user === null) {
return null;
} else {
return this.user.userName;
}
}
/**
*
*/
// get lang(): any {
// if (this.user === null) {
// return null;
// } else {
// return this.user.lang;
// }
// }
/**
*
*/
get loginName(): any {
if (this.user === null) {
return null;
} else {
console.log(this.user, '1111111');
return this.user.loginName;
}
}
get FactoryCode(): any {
if (this.factory === null) {
return null;
} else {
return this.factory.factoryCode;
}
}
get PoolName(): any {
if (this.factory === null) {
return null;
} else {
return this.factory.poolName;
}
}
/**
*
*/
// get factoryCode(): any {
// if (this.user === null) {
// return null;
// } else {
// return this.factoryCode.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 {
console.log(this.user);
return this.user;
}
}
get getFactory(): FactoryCode {
if (this.factory === null) {
throw new Error('当前无选择工厂');
} else {
return this.factory;
}
}
//获取菜单
get getMenus(): any {
if (this.user === null) {
throw new Error('当前无登录用户');
} else {
return this.user.menuList;
}
}
// 登录
@Action({ rawError: true })
async login({ username, password }: { username: string; password: string }) {
const requestData = {
username: username,
password: password,
};
return request.post(url.wmspda.system.login, requestData);
}
// 获取用户信息
@Action({ rawError: true })
async getInfo({ username }: { username: string }) {
const requestData = {
userName: username,
};
console.log(request.post(url.wmspda.system.getInfo, requestData), this.user);
return request.post(url.wmspda.system.getInfo, requestData);
}
// get parkName(): any {
// if (this.requestData === null) {
// return null;
// } else {
// return this.requestData.parkName;
// }
// }
// 登出
@Mutation
logout(): void {
// logout
this.user = null;
2 years ago
uni.removeStorageSync('userinfo');
//this.area = null;
uni.reLaunch({ url: page.login.login });
}
// 保存用户信息
@Mutation
setUser(user: User): void {
this.user = user;
}
@Mutation
setFactory(factory: FactoryCode): void {
this.factory = factory;
}
// 保存工作区信息
// @Mutation
// setArea(area: Area): void {
// this.area = area;
// }
4 years ago
//查询版本号
@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);