feat: 完善智慧停车综合管理平台源码
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { configure } from 'mobx';
|
||||
import MapConfig from './mapConfig';
|
||||
import User from './user';
|
||||
|
||||
configure({ enforceActions: 'observed' });
|
||||
|
||||
const user = new User();
|
||||
const mapConfig = new MapConfig();
|
||||
|
||||
export default { user, mapConfig };
|
||||
@@ -0,0 +1,50 @@
|
||||
import services from '@/services';
|
||||
import { CRS, ImageOverlay, type MapOptions, TileLayer } from 'leaflet';
|
||||
import { action, makeAutoObservable } from 'mobx';
|
||||
|
||||
class MapConfig {
|
||||
private _config: MapOptions | null = null;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
@action setConfig(config: MapOptions) {
|
||||
if (this._config != null) {
|
||||
Object.assign(this._config, config);
|
||||
} else {
|
||||
this._config = config;
|
||||
}
|
||||
}
|
||||
|
||||
// lazy fetch map config
|
||||
get config(): MapOptions {
|
||||
if (this._config != null) {
|
||||
return this._config;
|
||||
} else {
|
||||
this.fetchAndSetMapConfig().catch(console.error);
|
||||
return {
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
attributionControl: false,
|
||||
zoomControl: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async fetchAndSetMapConfig() {
|
||||
const data = (await services['GET /api/user/getMapConfig']()).data;
|
||||
this.setConfig({
|
||||
...data.mapOptions,
|
||||
crs: data.layer.type === 'tileLayer' ? CRS.EPSG3857 : CRS.Simple,
|
||||
layers: [
|
||||
data.layer.type === 'tileLayer'
|
||||
? new TileLayer(data.layer.url)
|
||||
: new ImageOverlay(data.layer.url, data.layer.bounds),
|
||||
],
|
||||
});
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export default MapConfig;
|
||||
@@ -0,0 +1,39 @@
|
||||
import { action, makeAutoObservable } from 'mobx';
|
||||
|
||||
export default class User {
|
||||
token = localStorage.getItem('user.token') ?? '';
|
||||
role = localStorage.getItem('user.role') ?? '';
|
||||
avatarURL = localStorage.getItem('user.avatarURL') ?? '';
|
||||
nickname = localStorage.getItem('user.nickname') ?? '';
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
@action setToken = (token: string) => {
|
||||
this.token = token;
|
||||
localStorage.setItem('user.token', token);
|
||||
};
|
||||
|
||||
@action setUserInfo = (userinfo: {
|
||||
avatarURL: string;
|
||||
nickname: string;
|
||||
role: string;
|
||||
}) => {
|
||||
this.avatarURL = userinfo.avatarURL;
|
||||
this.nickname = userinfo.nickname;
|
||||
this.role = userinfo.role;
|
||||
localStorage.setItem('user.avatarURL', userinfo.avatarURL);
|
||||
localStorage.setItem('user.nickname', userinfo.nickname);
|
||||
localStorage.setItem('user.role', userinfo.role);
|
||||
};
|
||||
|
||||
@action logoff = () => {
|
||||
this.setToken('');
|
||||
this.setUserInfo({ avatarURL: '', nickname: '', role: '' });
|
||||
};
|
||||
|
||||
getToken() {
|
||||
return this.token;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user