user:manage:upser
This commit is contained in:
parent
0490de1542
commit
8c5494cafe
|
|
@ -1,4 +1,5 @@
|
|||
import addressCheckers from './address';
|
||||
import tokenCheckers from './token';
|
||||
import userCheckers from './user';
|
||||
|
||||
export default [...addressCheckers, ...tokenCheckers];
|
||||
export default [...addressCheckers, ...tokenCheckers, ...userCheckers];
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
import { isMobile } from 'oak-domain/lib/utils/validator';
|
||||
import { OakInputIllegalException, Checker } from "oak-domain/lib/types";
|
||||
import { EntityDict } from 'oak-app-domain';
|
||||
import { checkAttributesNotNull } from '../utils/check';
|
||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||
|
||||
const checkers: Checker<EntityDict, 'user', GeneralRuntimeContext<EntityDict>> [] = [
|
||||
{
|
||||
type: 'data',
|
||||
action: 'create',
|
||||
entity: 'user',
|
||||
checker: async ({ operation }) => {
|
||||
const { action, data } = operation;
|
||||
if (data instanceof Array) {
|
||||
data.forEach(
|
||||
ele => {
|
||||
checkAttributesNotNull(ele, ['nickname']);
|
||||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
checkAttributesNotNull(data, ['nickname']);
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
export default checkers;
|
||||
|
|
@ -61,9 +61,14 @@ OakPage({
|
|||
goUserManageDetail(options: WechatMiniprogram.Touch) {
|
||||
const { id } = options.currentTarget.dataset;
|
||||
this.navigateTo({
|
||||
url: `detail/index`,
|
||||
url: 'detail/index',
|
||||
oakId: id,
|
||||
});
|
||||
}
|
||||
},
|
||||
goNewUser() {
|
||||
this.navigateTo({
|
||||
url: 'upsert/index',
|
||||
});
|
||||
},
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"navigationBarTitleText": "修改用户信息",
|
||||
"usingComponents": {
|
||||
"g-btn": "../../../../components/UI/g-btn/index",
|
||||
"g-input": "../../../../components/UI/g-input/index",
|
||||
"g-icon": "../../../../components/UI/g-icon/index",
|
||||
"g-panel": "../../../../components/UI/g-panel/index"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/** index.wxss **/
|
||||
@import "../../../../styles/cell.less";
|
||||
|
||||
.page-body {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
background-color: @background-color-base;
|
||||
}
|
||||
|
||||
.g-cell-hover:extend(.g-cell) {
|
||||
background-color: gainsboro;
|
||||
}
|
||||
|
||||
.focused {
|
||||
background-color: pink;
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
import { assign } from "lodash";
|
||||
|
||||
const GenderOptions = [
|
||||
{
|
||||
value: 'male', label: '男',
|
||||
},
|
||||
{
|
||||
value: 'female', label: '女',
|
||||
}
|
||||
];
|
||||
|
||||
const IDCardTypeOptions = [
|
||||
{
|
||||
value: 'ID-Card', label: '身份证',
|
||||
},
|
||||
{
|
||||
value: 'passport', label: '护照',
|
||||
},
|
||||
{
|
||||
value: 'Mainland-passport', label: '港澳通行证',
|
||||
}
|
||||
];
|
||||
|
||||
OakPage({
|
||||
path: 'user:manage:upsert',
|
||||
entity: 'user',
|
||||
projection: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
nickname: 1,
|
||||
birth: 1,
|
||||
gender: 1,
|
||||
avatar: 1,
|
||||
idCardType: 1,
|
||||
idNumber: 1,
|
||||
},
|
||||
isList: false,
|
||||
formData: async ([user]) => {
|
||||
const { birth, gender, idCardType } = user || {};
|
||||
const birthText = birth && (new Date(birth)).toLocaleDateString();
|
||||
const GenderDict = {
|
||||
male: '男',
|
||||
female: '女',
|
||||
};
|
||||
const genderText = gender && GenderDict[gender];
|
||||
const genderIndex = gender && GenderOptions.find(
|
||||
ele => ele.value === gender
|
||||
);
|
||||
const IdCardTypeDict = {
|
||||
'ID-Card': '身份证',
|
||||
'passport': '护照',
|
||||
'Mainland-passport': '港澳通行证',
|
||||
};
|
||||
const idCardTypeText = idCardType && IdCardTypeDict[idCardType];
|
||||
const idCardTypeIndex = idCardType && IDCardTypeOptions.find(
|
||||
ele => ele.value === gender
|
||||
);
|
||||
const now = new Date();
|
||||
return assign({}, user, {
|
||||
birthText,
|
||||
genderText,
|
||||
idCardTypeText,
|
||||
oldestBirthday: `${now.getFullYear() - 120}-01-01`,
|
||||
today: `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`,
|
||||
genderIndex,
|
||||
idCardTypeIndex,
|
||||
});
|
||||
},
|
||||
}, {
|
||||
data: {
|
||||
GenderOptions,
|
||||
IDCardTypeOptions,
|
||||
},
|
||||
methods: {
|
||||
setValue(input: WechatMiniprogram.Input) {
|
||||
const { target, detail } = input;
|
||||
const { dataset: { attr } } = target;
|
||||
const { value } = detail;
|
||||
this.setUpdateData(attr, value);
|
||||
},
|
||||
onBirthChange(e: WechatMiniprogram.PickerChange) {
|
||||
const { value } = e.detail;
|
||||
const birth = new Date(value as string);
|
||||
birth.setHours(0);
|
||||
birth.setMinutes(0);
|
||||
birth.setSeconds(0);
|
||||
birth.setMilliseconds(0);
|
||||
this.setUpdateData('birth', birth);
|
||||
},
|
||||
onGenderChange(e: WechatMiniprogram.PickerChange) {
|
||||
const { value } = e.detail;
|
||||
this.setUpdateData('gender', GenderOptions[value as unknown as number].value)
|
||||
},
|
||||
onIdCardTypeChange(e: WechatMiniprogram.PickerChange) {
|
||||
const { value } = e.detail;
|
||||
this.setUpdateData('idCardType', IDCardTypeOptions[value as unknown as number].value)
|
||||
},
|
||||
async confirm() {
|
||||
await this.execute(this.data.oakId ? 'update': 'create', () => {
|
||||
if (this.data.oakFrom === 'user:manage:list') {
|
||||
wx.navigateBack();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<!-- index.wxml -->
|
||||
<view class="page-body">
|
||||
<g-panel>
|
||||
<g-input error="{{!!oakFocused.nickname}}" oak:value="nickname" title="昵称 *" placeholder="昵称" confirm-type="next" bind:change="setValue" />
|
||||
<g-input error="{{!!oakFocused.name}}" oak:value="name" title="姓名" placeholder="姓名" confirm-type="next" bind:change="setValue" />
|
||||
<picker mode="date" bindchange="onBirthChange" start="{{oldestBirthday}}" end="{{today}}">
|
||||
<view class="g-cell {{oakFocused.birth}}" hover-class="g-cell-hover">
|
||||
<view class="g-input-title">出生日期</view>
|
||||
<view class="g-input-input" style="display: flex; flex: 1; align-items: center; justify-content:space-between">
|
||||
<text>{{birthText || '请选择'}}</text>
|
||||
</view>
|
||||
<g-icon name="chevron_right" />
|
||||
</view>
|
||||
</picker>
|
||||
<picker mode="selector" range="{{GenderOptions}}" range-key="label" value="{{genderIndex}}" bindchange="onGenderChange">
|
||||
<view class="g-cell {{oakFocused.gender}}" hover-class="g-cell-hover">
|
||||
<view class="g-input-title">性别</view>
|
||||
<view class="g-input-input" style="display: flex; flex: 1; align-items: center; justify-content:space-between">
|
||||
<text>{{genderText || '请选择'}}</text>
|
||||
</view>
|
||||
<g-icon name="chevron_right" />
|
||||
</view>
|
||||
</picker>
|
||||
<picker mode="selector" range="{{IDCardTypeOptions}}" range-key="label" value="{{idCardTypeIndex}}" bindchange="onIdCardTypeChange">
|
||||
<view class="g-cell {{oakFocused.idCardType}}" hover-class="g-cell-hover">
|
||||
<view class="g-input-title">证件类别</view>
|
||||
<view class="g-input-input" style="display: flex; flex: 1; align-items: center; justify-content:space-between">
|
||||
<text>{{idCardTypeText || '请选择'}}</text>
|
||||
</view>
|
||||
<g-icon name="chevron_right" />
|
||||
</view>
|
||||
</picker>
|
||||
<g-input error="{{!!oakFocused.idCardNumber}}" oak:value="idCardNumber" title="证件号" placeholder="请输入证件号码" confirm-type="done" bind:change="setValue" />
|
||||
</g-panel>
|
||||
<view style="flex: 1" />
|
||||
<g-btn type="primary" long="true" class="{{ oakExecuting ? 'g-btn-loading' : ''}} {{ !oakDirty ? 'g-btn-disabled' : ''}}" disabled="{{oakExecuting || !oakDirty}}" bind:click="confirm">
|
||||
<view class="g-btn-loading-inner" wx:if="{{oakExecuting}}"></view>
|
||||
确定
|
||||
</g-btn>
|
||||
</view>
|
||||
Loading…
Reference in New Issue