126 lines
4.0 KiB
JavaScript
126 lines
4.0 KiB
JavaScript
import {
|
||
Query,
|
||
QueryTask,
|
||
QueryType,
|
||
EditTask,
|
||
EditType,
|
||
Operator,
|
||
CellsysType,
|
||
} from './cellsysUtil.js';
|
||
import CellsysOfflinePolygonType from './cellsysOfflinePolygonType';
|
||
import CellsysEquipment from './cellsysEquipment';
|
||
import CellsysMessage from './cellsysMessage';
|
||
import CellsysPolygon from './cellsysPolygon';
|
||
|
||
class CellsysUser {
|
||
constructor(params) {
|
||
this.cellsysType = CellsysType.User;
|
||
if (!params) {
|
||
params = {};
|
||
}
|
||
this.userId = params.user_id;
|
||
this.userStatus = params.user_status;
|
||
this.userName = params.username;
|
||
this.realName = params.realname;
|
||
this.role = params.role;
|
||
|
||
this.mobile = params.mobile;
|
||
this.email = params.email;
|
||
this.openId = params.openid;
|
||
this.isUserName = params.is_username;
|
||
this.isMobile = params.is_mobile;
|
||
this.oauth = params.oauth;
|
||
this.avatar = params.avatar;
|
||
this.gender = params.gender;
|
||
this.birthday = params.birthday;
|
||
this.orgId = params.org_id;
|
||
this.orgStatus = params.org_status; //组织本身状态
|
||
this.userOrgStatus = params.user_org_status;
|
||
this.userOrgType = params.user_org_type;
|
||
this.memberTypeId = params.member_type_id;
|
||
this.memberTypeName = params.member_type_name;
|
||
this.orgFeedBack = params.feedback;
|
||
this.groups = params.groups;
|
||
this.macId = params.macid; //用户绑定的设备
|
||
// this.status = params.status
|
||
// this.orgType = params.orgType // 0:两种申请都被拒绝 1:创建组织被拒绝 2:加入组织被拒绝
|
||
window.CELLSYSUSER = this || {}; //cellsysSDK不应该依赖于vue才能访问到cellsysUser对象,因此引入window全局属性来缓存cellsysUser对象
|
||
}
|
||
|
||
get isAdmin() {
|
||
return /_admin$/.test(this.role);
|
||
}
|
||
|
||
setId(value) {
|
||
this.userId = value;
|
||
}
|
||
|
||
queryMessageRecord(params = {}) {
|
||
let query = new Query();
|
||
let { pageInfo, filters, order, httpConfig } = params;
|
||
if (pageInfo) {
|
||
query.setCurrPage(pageInfo.currPage);
|
||
query.setPageSize(pageInfo.pageSize);
|
||
}
|
||
if (filters && filters.length > 0) {
|
||
filters.forEach((item) => {
|
||
query.addFilter(item['name'], item['operator'], item['value'], item['type']);
|
||
});
|
||
}
|
||
if (order) {
|
||
query.setOrder(order);
|
||
} else {
|
||
query.setOrder({ id: 'desc' });
|
||
}
|
||
|
||
if (httpConfig) {
|
||
query.setHttpConfig(httpConfig);
|
||
}
|
||
let queryTask = new QueryTask(QueryType.MessageRecord, pageInfo ? true : false);
|
||
return new Promise((resolve, reject) => {
|
||
queryTask
|
||
.execute(query)
|
||
.then((res) => {
|
||
if (res && res.data) {
|
||
res.data = res.data.map((item) => {
|
||
return new CellsysMessage(item);
|
||
});
|
||
}
|
||
resolve(res);
|
||
})
|
||
.catch((err) => {
|
||
reject(err);
|
||
});
|
||
});
|
||
}
|
||
|
||
queryBindingDevice() {
|
||
let query = new Query();
|
||
query.setPageSize(0);
|
||
query.addFilter('macid', Operator.Equals, this.macId);
|
||
let queryTask = new QueryTask(QueryType.Equipment);
|
||
return new Promise((resolve, reject) => {
|
||
queryTask
|
||
.execute(query)
|
||
.then((res) => {
|
||
let equipments = res.map((item) => {
|
||
return new CellsysEquipment(item);
|
||
});
|
||
resolve(equipments);
|
||
})
|
||
.catch((err) => {
|
||
reject(err);
|
||
});
|
||
});
|
||
}
|
||
|
||
//将指定的聊天消息设置成已读
|
||
setMessageRead(ids = []) {
|
||
let editTask = new EditTask(EditType.ChatPrivateRead);
|
||
editTask.addParam('_ids', ids);
|
||
return editTask.execute();
|
||
}
|
||
}
|
||
|
||
export default CellsysUser;
|