import { String, Int, Text, Boolean, Datetime } from 'oak-domain/lib/types/DataType'; import { ActionDef } from 'oak-domain/lib/types/Action'; import { EntityShape } from 'oak-domain/lib/types/Entity'; import { EntityDesc } from 'oak-domain/lib/types/EntityDesc'; import { Schema as User } from 'oak-domain/lib/entities/User'; export interface Schema extends User { passwordSha1?: Text; birth?: Datetime; gender?: 'male' | 'female'; idCardType?: 'ID-Card' | 'passport' | 'Mainland-passport'; idNumber?: String<32>; isRoot?: Boolean; hasPassword?: Boolean; }; export type IdAction = 'verify' | 'accept' | 'reject'; export type IdState = 'unverified' | 'verified' | 'verifying'; export const IdActionDef: ActionDef = { stm: { verify: ['unverified', 'verifying'], accept: [['unverified', 'verifying'], 'verified'], reject: [['verifying', 'verified'], 'unverified'], }, is: 'unverified', }; export type UserAction = 'activate' | 'disable' | 'enable' | 'mergeTo' | 'mergeFrom'; export type UserState = 'shadow' | 'normal' | 'disabled' | 'merged'; export const UserActionDef: ActionDef = { stm: { activate: ['shadow', 'normal'], disable: [['normal', 'shadow'], 'disabled'], enable: ['disabled', 'normal'], mergeTo: [['normal', 'shadow'], 'merged'], mergeFrom: ['normal', 'normal'], }, }; export type Action = UserAction | IdAction; export const entityDesc: EntityDesc< Schema, Action, '', { userState: UserState; idState: IdState; gender: Required['gender']; idCardType: Required['idCardType']; } > = { locales: { zh_CN: { name: '用户', attr: { name: '姓名', nickname: '昵称', birth: '生日', password: '密码', passwordSha1: 'sha1加密密码', gender: '性别', idCardType: '证件类型', idNumber: '证件号码', ref: '指向用户', userState: '用户状态', idState: '认证状态', isRoot: '是否超级用户', hasPassword: '用户是否存在密码' }, action: { activate: '激活', accept: '同意', verify: '认证', reject: '拒绝', enable: '启用', disable: '禁用', mergeTo: '合并', mergeFrom: '使合并', }, v: { userState: { shadow: '未激活', normal: '正常', disabled: '禁用', merged: '已被合并', }, idState: { unverified: '未认证', verifying: '认证中', verified: '已认证', }, gender: { male: '男', female: '女', }, idCardType: { 'ID-Card': '身份证', passport: '护照', 'Mainland-passport': '港澳台通行证', }, }, }, }, indexes: [ { name: 'index_birth', attributes: [ { name: 'birth', direction: 'ASC', }, ], }, { name: 'index_fulltext', attributes: [ { name: 'name', }, { name: 'nickname', }, ], config: { type: 'fulltext', parser: 'ngram', }, }, { name: 'index_userState_refId', attributes: [ { name: 'userState', }, { name: 'ref', }, ], }, ], style: { icon: { verify: '', accept: '', reject: '', activate: '', enable: '', disable: '', mergeTo: '', mergeFrom: '', }, color: { userState: { normal: '#0000FF', disabled: '#FF0000', merged: '#9A9A9A', shadow: '#D3D3D3', }, idState: { unverified: '#FF0000', verified: '#0000FF', verifying: '#EEE8AA', }, gender: { male: '#0000FF', female: '#EE82EE', }, idCardType: { 'ID-Card': '#E0FFFF', 'Mainland-passport': '#2E8B57', passport: '#2F4F4F', }, }, }, };