204 lines
8.7 KiB
JavaScript
204 lines
8.7 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var tslib_1 = require("tslib");
|
|
var string_1 = require("oak-domain/lib/utils/string");
|
|
var extraFile_1 = require("../../../utils/extraFile");
|
|
exports.default = OakComponent({
|
|
entity: 'user',
|
|
projection: function (_a) {
|
|
var props = _a.props;
|
|
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
var entity, relations, entityId, entityStr;
|
|
var _b, _c, _d;
|
|
return tslib_1.__generator(this, function (_e) {
|
|
entity = props.entity, relations = props.relations, entityId = props.entityId;
|
|
entityStr = (0, string_1.firstLetterUpperCase)(entity);
|
|
return [2 /*return*/, (_b = {
|
|
id: 1,
|
|
name: 1,
|
|
nickname: 1,
|
|
mobile$user: {
|
|
$entity: 'mobile',
|
|
data: {
|
|
id: 1,
|
|
userId: 1,
|
|
mobile: 1,
|
|
},
|
|
}
|
|
},
|
|
_b["user".concat(entityStr, "$user")] = {
|
|
$entity: "user".concat(entityStr),
|
|
data: (_c = {
|
|
id: 1,
|
|
userId: 1
|
|
},
|
|
_c["".concat(entity, "Id")] = 1,
|
|
_c.relation = 1,
|
|
_c),
|
|
filter: (_d = {
|
|
relation: {
|
|
$in: relations,
|
|
}
|
|
},
|
|
_d["".concat(entity, "Id")] = entityId,
|
|
_d),
|
|
},
|
|
_b.extraFile$entity = {
|
|
$entity: 'extraFile',
|
|
data: {
|
|
id: 1,
|
|
tag1: 1,
|
|
origin: 1,
|
|
bucket: 1,
|
|
objectId: 1,
|
|
filename: 1,
|
|
extra1: 1,
|
|
type: 1,
|
|
entity: 1,
|
|
extension: 1,
|
|
},
|
|
filter: {
|
|
tag1: 'avatar',
|
|
},
|
|
indexFrom: 0,
|
|
count: 1,
|
|
},
|
|
_b)];
|
|
});
|
|
});
|
|
},
|
|
filters: [
|
|
// 由调用者注入oakFilter
|
|
],
|
|
isList: true,
|
|
formData: function (_a) {
|
|
var _b;
|
|
var users = _a.data, props = _a.props, features = _a.features;
|
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
var entity, entityStr, filter, _c;
|
|
return tslib_1.__generator(this, function (_d) {
|
|
switch (_d.label) {
|
|
case 0:
|
|
entity = props.entity;
|
|
entityStr = (0, string_1.firstLetterUpperCase)(entity);
|
|
_c = this.state.oakFullpath;
|
|
if (!_c) return [3 /*break*/, 2];
|
|
return [4 /*yield*/, this.getFilterByName('name')];
|
|
case 1:
|
|
_c = (_d.sent());
|
|
_d.label = 2;
|
|
case 2:
|
|
filter = _c;
|
|
return [2 /*return*/, {
|
|
users: users === null || users === void 0 ? void 0 : users.map(function (ele) {
|
|
var _a;
|
|
var _b = ele || {}, mobile$user = _b.mobile$user, extraFile$entity = _b.extraFile$entity;
|
|
var userEntity = ele["user".concat(entityStr, "$user")];
|
|
var mobile = mobile$user && ((_a = mobile$user[0]) === null || _a === void 0 ? void 0 : _a.mobile);
|
|
var avatar = extraFile$entity &&
|
|
extraFile$entity[0] &&
|
|
(0, extraFile_1.composeFileUrl)(extraFile$entity[0]);
|
|
var relations = userEntity === null || userEntity === void 0 ? void 0 : userEntity.map(function (ele) { return ele.relation; });
|
|
var hasRelation = props.relations.map(function (ele2) {
|
|
return relations.includes(ele2);
|
|
});
|
|
var user2 = Object.assign({}, ele, {
|
|
mobile: mobile,
|
|
avatar: avatar,
|
|
relations: relations,
|
|
hasRelation: hasRelation,
|
|
});
|
|
return user2;
|
|
}),
|
|
searchValue: (filter === null || filter === void 0 ? void 0 : filter.$or) &&
|
|
((_b = filter.$or[0]) === null || _b === void 0 ? void 0 : _b.name.$includes),
|
|
}];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
properties: {
|
|
entity: String,
|
|
entityId: String,
|
|
relations: Array,
|
|
},
|
|
data: {
|
|
searchValue: '',
|
|
},
|
|
lifetimes: {},
|
|
methods: {
|
|
searchChange: function (input) {
|
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
var value;
|
|
return tslib_1.__generator(this, function (_a) {
|
|
value = this.resolveInput(input).value;
|
|
this.addNamedFilter({
|
|
filter: {
|
|
$or: [
|
|
{
|
|
name: {
|
|
$includes: value,
|
|
},
|
|
},
|
|
{
|
|
nickname: {
|
|
$includes: value,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
'#name': 'name',
|
|
});
|
|
return [2 /*return*/];
|
|
});
|
|
});
|
|
},
|
|
searchCancel: function () {
|
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
return tslib_1.__generator(this, function (_a) {
|
|
this.removeNamedFilterByName('name');
|
|
return [2 /*return*/];
|
|
});
|
|
});
|
|
},
|
|
searchConfirm: function () {
|
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
return tslib_1.__generator(this, function (_a) {
|
|
this.refresh();
|
|
return [2 /*return*/];
|
|
});
|
|
});
|
|
},
|
|
onChange: function (input) {
|
|
var _a = this.resolveInput(input), dataset = _a.dataset, value = _a.value;
|
|
var _b = dataset, userId = _b.id, relation = _b.relation, index = _b.index;
|
|
this.onChangeValue(value, relation, index);
|
|
},
|
|
onChangeValue: function (value, relation, index) {
|
|
var _a;
|
|
var _b = this.props, entity = _b.entity, entityId = _b.entityId;
|
|
var entityStr = (0, string_1.firstLetterUpperCase)(entity);
|
|
this.toggleNode((_a = {
|
|
relation: relation
|
|
},
|
|
_a["".concat(entity, "Id")] = entityId,
|
|
_a), value, "".concat(index, ".user").concat(entityStr, "$user"));
|
|
},
|
|
confirm: function () {
|
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
return tslib_1.__generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0: return [4 /*yield*/, this.execute('grant')];
|
|
case 1:
|
|
_a.sent();
|
|
return [4 /*yield*/, this.navigateBack()];
|
|
case 2:
|
|
_a.sent();
|
|
return [2 /*return*/];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|
|
});
|