userRelation-onUser的实现
This commit is contained in:
parent
336b46eaa4
commit
f2ee3efa6d
|
|
@ -22,7 +22,7 @@ export default OakPage({
|
|||
properties: {
|
||||
entity: String,
|
||||
entityId: String,
|
||||
relations: String,
|
||||
relations: Array,
|
||||
type: String,
|
||||
},
|
||||
data: {},
|
||||
|
|
@ -31,9 +31,6 @@ export default OakPage({
|
|||
this.setUpdateData('entity', this.props.entity);
|
||||
this.setUpdateData('entityId', this.props.entityId);
|
||||
this.setUpdateData('type', this.props.type);
|
||||
this.setState({
|
||||
relationArr: JSON.parse(this.props.relations),
|
||||
});
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<view class="page-body">
|
||||
<view class="cell-col">
|
||||
<radio-group bindchange="radioChange" class="test">
|
||||
<label class="label" wx:for="{{relationArr}}" wx:key="*this">
|
||||
<label class="label" wx:for="{{relations}}" wx:key="*this">
|
||||
<view>
|
||||
<radio value="{{item}}" color="#2d8cf0" />
|
||||
</view>
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
<!-- index.wxml -->
|
||||
<view class="container">
|
||||
<view class="primary-bg"></view>
|
||||
<view class="white-bg">
|
||||
<view class="content">
|
||||
<image mode="aspectFill" class="img" src="{{avatar}}" lazy-load></image>
|
||||
<text class="name">{{name || nickname || '--'}}</text>
|
||||
<text class="mobile">{{mobile || '--'}}</text>
|
||||
<divider />
|
||||
<view wx:if="{{relationArr.length}}" class="tag-view">
|
||||
<l-tag class="tag" plain="{{true}}" wx:for="{{relationArr}}" wx:for-index="index" wx:for-item="item" wx:key="index">
|
||||
{{item}}
|
||||
</l-tag>
|
||||
</view>
|
||||
<view wx:else>
|
||||
<text class="mobile">-无权限-</text>
|
||||
</view>
|
||||
<view class="btn-view">
|
||||
<l-button type="default" bind:lintap="handleShow">更新权限</l-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<l-dialog show="{{show}}" width="700" type="confirm" title="选择权限" confirm-text="确定" cancel-text="取消">
|
||||
<view class="check-view">
|
||||
<l-checkbox-group bind:linchange="onChangeTap" wx:for="{{relationArr2}}" wx:key="index">
|
||||
<l-checkbox key="{{item[0]}}" checked="{{item[1]}}" placement="right" style="border-top: 0.5px solid rgba(0,0,0,0.1); padding:20rpx">
|
||||
{{item[0]}}
|
||||
</l-checkbox>
|
||||
</l-checkbox-group>
|
||||
</view>
|
||||
</l-dialog>
|
||||
</view>
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<!-- index.wxml -->
|
||||
<view class="container">
|
||||
<view class="search-bar">
|
||||
<l-search-bar placeholder="搜索" cancel-text="搜索" shape="circle" value="{{searchValue}}" bind:lincancel="searchConfirm" bind:linclear="searchCancel" bind:linchange="searchChange" bind:linconfirm="searchConfirm" />
|
||||
</view>
|
||||
<block wx:if="{{ users && users.length > 0 }}">
|
||||
<block wx:for="{{users}}" wx:key="index" wx:for-item="item">
|
||||
<l-card l-class="card-view" title="{{item.name}}" describe="{{item.nickname}}" data-id="{{item.id}}" bind:tap="handleCardClick" type="avatar" image="{{item.avatar}}">
|
||||
<!-- 此处为content -->
|
||||
<view class="content">
|
||||
<view class="row">
|
||||
<block wx:for="{{item.relations}}" wx:for-index="relationIndex" wx:for-item="relation" wx:key="relationIndex">
|
||||
<l-tag class="tag" shape="circle" plain="{{true}}">{{relation}}</l-tag>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</l-card>
|
||||
</block>
|
||||
<block wx:if="{{isRoot}}">
|
||||
<fab bind:click="goUpsertUser">
|
||||
<l-icon name="add" type="material" color="#fff" size="48" />
|
||||
</fab>
|
||||
</block>
|
||||
</block>
|
||||
<block wx:elif="{{isRoot}}">
|
||||
<l-status-show show="{{true}}" type="data" button-text="添加人员" bind:lintap="goUpsertUser"></l-status-show>
|
||||
</block>
|
||||
</view>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"navigationBarTitleText": "权限详情",
|
||||
"navigationBarTitleText": "修改权限",
|
||||
"usingComponents": {
|
||||
"l-button": "../../../lin-ui/button/index",
|
||||
"l-tag": "../../../lin-ui/tag/index",
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
"fab": "../../../components/fab/index",
|
||||
"l-dialog": "../../../lin-ui/dialog/index",
|
||||
"l-checkbox-group": "../../../lin-ui/checkbox-group/index",
|
||||
"l-checkbox": "../../../lin-ui/checkbox/index"
|
||||
"l-checkbox": "../../../lin-ui/checkbox/index",
|
||||
"l-switch": "../../../lin-ui/switch/index"
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ page {
|
|||
|
||||
.primary-bg {
|
||||
width: 100%;
|
||||
height: 100rpx;
|
||||
height: 140rpx;
|
||||
background-color: @default-color;
|
||||
}
|
||||
.img {
|
||||
|
|
@ -78,3 +78,20 @@ page {
|
|||
flex-direction: column;
|
||||
flex: 1;
|
||||
}
|
||||
.list {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
.singleRelationItem {
|
||||
display: flex;
|
||||
padding: 10rpx;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
.name {
|
||||
color: @text-color;
|
||||
flex: 1;
|
||||
margin-right: 10rpx;
|
||||
};
|
||||
}
|
||||
|
|
@ -5,10 +5,9 @@ OakPage(
|
|||
{
|
||||
path: 'userRelation:detail',
|
||||
entity: 'user',
|
||||
projection: async ({onLoadOptions}) => {
|
||||
const { entity, entityIds, nameExpression, relations } = onLoadOptions;
|
||||
projection: async ({ props }) => {
|
||||
const { entity, entityIds, nameExpression, relations } = props;
|
||||
const entityStr = firstLetterUpperCase(entity!);
|
||||
const entityIds2 = JSON.parse(entityIds!) as string[];
|
||||
return {
|
||||
id: 1,
|
||||
name: 1,
|
||||
|
|
@ -31,10 +30,10 @@ OakPage(
|
|||
},
|
||||
filter: {
|
||||
[`${entity}Id`]: {
|
||||
$in: entityIds2,
|
||||
$in: entityIds,
|
||||
},
|
||||
relation: {
|
||||
$in: JSON.parse(relations!),
|
||||
$in: relations!,
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -62,15 +61,15 @@ OakPage(
|
|||
},
|
||||
isList: false,
|
||||
formData: async function ({ data: user, props }) {
|
||||
const { entity, relations, entityIds } = props;
|
||||
const { entity, entityIds, relations } = props;
|
||||
const entityStr = firstLetterUpperCase(entity!);
|
||||
const { name, nickname, mobile, [`user${entityStr}$user`]: relationRows, extraFile$entity } = user!;
|
||||
// entity按id聚集
|
||||
const entityIds2 = JSON.parse(entityIds!) as string[];
|
||||
const entityRows = entityIds2.map(
|
||||
(id, idx) => ({
|
||||
const { entityRows } = this.state;
|
||||
const entityRowData = entityIds!.map(
|
||||
(id) => ({
|
||||
id,
|
||||
name: entityNames[idx],
|
||||
name: entityRows.find(ele => ele.id === id)?.$expr,
|
||||
relations: (relationRows as {
|
||||
relation: string;
|
||||
[A: string]: string;
|
||||
|
|
@ -81,44 +80,42 @@ OakPage(
|
|||
)
|
||||
})
|
||||
);
|
||||
const avatar = extraFile$entity![0] && composeFileUrl(extraFile$entity![0]);
|
||||
const avatar = (extraFile$entity![0] && composeFileUrl(extraFile$entity![0])) as string;
|
||||
return {
|
||||
name,
|
||||
nickname,
|
||||
avatar,
|
||||
relations,
|
||||
entityRows,
|
||||
entityRowData,
|
||||
mobile,
|
||||
singleRelation: relations!.length === 1,
|
||||
}
|
||||
},
|
||||
properties: {
|
||||
entity: String,
|
||||
entityIds: String,
|
||||
nameExpression: String,
|
||||
relations: String,
|
||||
entityNames: String,
|
||||
entityIds: Array,
|
||||
nameExpression: Object,
|
||||
relations: Array,
|
||||
},
|
||||
data: {
|
||||
show: false,
|
||||
relationArr2: [],
|
||||
entityRows: [] as any[],
|
||||
},
|
||||
methods: {
|
||||
handleShow() {
|
||||
this.setState({
|
||||
show: true,
|
||||
});
|
||||
},
|
||||
onChangeTap(input: WechatMiniprogram.Touch) {
|
||||
const { key, checked } = this.resolveInput(input, ['key', 'checked']);
|
||||
const { relationArr2 } = this.state;
|
||||
relationArr2.forEach((ele: any) => {
|
||||
if (ele[0] === key) {
|
||||
ele[1] = checked;
|
||||
async onLoad() {
|
||||
const { nameExpression, entity, entityIds } = this.props;
|
||||
const entityRows = await this.features.cache.get(entity as any, {
|
||||
data: {
|
||||
id: 1,
|
||||
$expr: nameExpression,
|
||||
},
|
||||
filter: {
|
||||
id: {
|
||||
$in: entityIds,
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
this.setState({
|
||||
relationArr2
|
||||
})
|
||||
entityRows,
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<!-- index.wxml -->
|
||||
<view class="container">
|
||||
<view class="primary-bg"></view>
|
||||
<view class="white-bg">
|
||||
<view class="content">
|
||||
<image mode="aspectFill" class="img" src="{{avatar}}" lazy-load></image>
|
||||
<text class="name">{{name || nickname || '--'}}</text>
|
||||
<text class="mobile">{{mobile || '--'}}</text>
|
||||
<divider />
|
||||
<block wx:if="{{singleRelation}}">
|
||||
<view class="list" wx:for="{{entityRowData}}">
|
||||
<view class="singleRelationItem">
|
||||
<view class="name">{{item.name}}</view>
|
||||
<l-switch />
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:else>
|
||||
222
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"navigationBarTitleText": "人员管理",
|
||||
"navigationBarTitleText": "修改权限",
|
||||
"usingComponents": {
|
||||
"l-button": "../../../lin-ui/button/index",
|
||||
"l-card": "../../../lin-ui/card/index",
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
"l-status-show": "../../../lin-ui/status-show/index",
|
||||
"l-search-bar": "../../../lin-ui/search-bar/index",
|
||||
"l-price": "../../../lin-ui/price/index",
|
||||
"l-switch": "../../../lin-ui/switch/index",
|
||||
"divider": "../../../components/divider/index",
|
||||
"fab": "../../../components/fab/index"
|
||||
}
|
||||
|
|
@ -32,17 +32,26 @@ page {
|
|||
.content {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
font-size: 28rpx;
|
||||
color: @text-color;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
|
||||
.relation-item {
|
||||
display: flex;
|
||||
padding: 10rpx;
|
||||
flex-direction: row;
|
||||
font-size: 28rpx;
|
||||
color: @text-color;
|
||||
}
|
||||
}
|
||||
|
||||
.tag {
|
||||
margin-right: 8rpx;
|
||||
.btn-container {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
.btn {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@ export default OakPage(
|
|||
{
|
||||
path: 'userRelation:list',
|
||||
entity: 'user',
|
||||
projection: async ({onLoadOptions}) => {
|
||||
const { entity } = onLoadOptions;
|
||||
const entityStr = entity && entity.charAt(0).toUpperCase() + entity.substring(1);
|
||||
projection: async ({ props }) => {
|
||||
const { entity } = props;
|
||||
const entityStr = firstLetterUpperCase(entity!);
|
||||
return {
|
||||
id: 1,
|
||||
name: 1,
|
||||
|
|
@ -28,6 +28,12 @@ export default OakPage(
|
|||
[`${entity}Id`]: 1,
|
||||
relation: 1,
|
||||
},
|
||||
filter: {
|
||||
relation: {
|
||||
$in: props.relations!,
|
||||
},
|
||||
[`${entity}Id`]: props.entityId!,
|
||||
}
|
||||
},
|
||||
extraFile$entity: {
|
||||
$entity: 'extraFile',
|
||||
|
|
@ -52,39 +58,17 @@ export default OakPage(
|
|||
};
|
||||
},
|
||||
filters: [
|
||||
// 暂时注掉
|
||||
/* {
|
||||
filter: async ({ onLoadOptions }) => {
|
||||
const { entityId, relations, entity } = onLoadOptions;
|
||||
const entityStr = entity && entity.charAt(0).toUpperCase() + entity.substring(1);
|
||||
const userRelationFilter = {
|
||||
[`${entity}Id`]: entityId,
|
||||
};
|
||||
return {
|
||||
id: {
|
||||
$in: {
|
||||
entity: `user${entityStr}`,
|
||||
data: {
|
||||
userId: 1,
|
||||
},
|
||||
filter: userRelationFilter,
|
||||
},
|
||||
},
|
||||
} as any;
|
||||
},
|
||||
}, */
|
||||
// 由调用者注入oakFilter
|
||||
],
|
||||
isList: true,
|
||||
formData: async function ({ data: users, props, features }) {
|
||||
const { entity } = props;
|
||||
const entityStr = firstLetterUpperCase(entity!);
|
||||
|
||||
const isRoot = await features.token.isRoot();
|
||||
const filter = await this.getFilterByName('name');
|
||||
|
||||
return {
|
||||
users: users?.map((ele: any) => {
|
||||
const { mobile$user, extraFile$entity } =
|
||||
const { mobile$user, extraFile$entity } =
|
||||
ele || {};
|
||||
const userEntity = ele![`user${entityStr}$user`];
|
||||
const mobile = mobile$user && mobile$user[0]?.mobile;
|
||||
|
|
@ -93,27 +77,28 @@ export default OakPage(
|
|||
extraFile$entity[0] &&
|
||||
composeFileUrl(extraFile$entity[0]);
|
||||
const relations = userEntity?.map((ele: any) => ele.relation);
|
||||
const hasRelation: boolean[] = this.props.relations.map(ele2 => relations.includes(ele2));
|
||||
const user2 = Object.assign({}, ele, {
|
||||
mobile,
|
||||
avatar,
|
||||
relations,
|
||||
hasRelation,
|
||||
});
|
||||
return user2;
|
||||
}),
|
||||
searchValue: (
|
||||
filter?.$or as [{ name: { $includes: string } }]
|
||||
)[0].name.$includes,
|
||||
isRoot,
|
||||
};
|
||||
},
|
||||
properties: {
|
||||
entity: String,
|
||||
entityIds: String,
|
||||
relations: String,
|
||||
nameExpression: String,
|
||||
entityId: String,
|
||||
relations: Array,
|
||||
},
|
||||
data: {
|
||||
searchValue: '',
|
||||
singleRelation: false,
|
||||
},
|
||||
lifetimes: {},
|
||||
methods: {
|
||||
|
|
@ -143,25 +128,24 @@ export default OakPage(
|
|||
async searchConfirm() {
|
||||
this.refresh();
|
||||
},
|
||||
goUpsertUser() {
|
||||
const { entity, entityIds } = this.props;
|
||||
this.navigateTo({
|
||||
url: '../../user/manage/upsert/index',
|
||||
});
|
||||
},
|
||||
handleCardClick(event: any) {
|
||||
const { entity, entityIds, nameExpression, relations } = this.props;
|
||||
const { dataset } = this.resolveInput(event);
|
||||
const { id } = dataset!;
|
||||
this.navigateTo({
|
||||
url: '../detail/index',
|
||||
oakId: id,
|
||||
entity,
|
||||
entityIds,
|
||||
nameExpression,
|
||||
relations,
|
||||
});
|
||||
onChange(input: any) {
|
||||
const { dataset, checked } = this.resolveInput(input, ['checked']);
|
||||
const { id: userId, relation, index } = dataset as {
|
||||
id: string,
|
||||
relation: string,
|
||||
index: number;
|
||||
};
|
||||
const { entity, entityId } = this.props;
|
||||
const entityStr = firstLetterUpperCase(entity!);
|
||||
this.toggleNode({
|
||||
relation,
|
||||
[`${entity}Id`]: entityId,
|
||||
}, checked, `${index}.user${entityStr}$user`)
|
||||
},
|
||||
async confirm() {
|
||||
await this.execute();
|
||||
await this.navigateBack();
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<!-- index.wxml -->
|
||||
<view class="container">
|
||||
<view class="search-bar">
|
||||
<l-search-bar placeholder="搜索" cancel-text="搜索" shape="circle" value="{{searchValue}}" bind:lincancel="searchConfirm" bind:linclear="searchCancel" bind:linchange="searchChange" bind:linconfirm="searchConfirm" />
|
||||
</view>
|
||||
<block wx:if="{{ users && users.length > 0 }}">
|
||||
<block wx:for="{{users}}" wx:for-index="index" wx:for-item="item" wx:key="idx">
|
||||
<l-card l-class="card-view" title="{{item.name}}" describe="{{item.nickname}}" data-id="{{item.id}}" bind:tap="handleCardClick" type="avatar" image="{{item.avatar}}">
|
||||
<block wx:if="{{singleRelation}}">
|
||||
<view slot="more">
|
||||
<l-switch />
|
||||
</view>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<divider />
|
||||
<view class="content">
|
||||
<block wx:for="{{relations}}" wx:key="idx" wx:for-index="index2" wx:for-item="relation">
|
||||
<view class="relation-item">
|
||||
<text>{{relation}}</text>
|
||||
<l-switch checked="{{item.hasRelation[index2]}}" bind:linchange="onChange" data-id="{{item.id}}" data-relation="{{relation}}" data-index="{{index}}" />
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</block>
|
||||
</l-card>
|
||||
</block>
|
||||
<view class="btn-container">
|
||||
<l-button icon="research" size="long" class="btn" icon-size="20" icon-color="#fff" bind:lintap="goSearchUser">搜索人员</l-button>
|
||||
<l-button type="success" size="long" class="btn" bind:lintap="confirm" disabled="{{!oakDirty}}">确定</l-button>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<l-status-show show="{{true}}" type="data" button-text="搜索人员" bind:lintap="goSearchUser"></l-status-show>
|
||||
</block>
|
||||
</view>
|
||||
Loading…
Reference in New Issue