tokenlogin适配web

This commit is contained in:
Xu Chang 2022-07-08 14:42:28 +08:00
parent 375ee566d3
commit c20791a4ed
16 changed files with 108 additions and 94 deletions

View File

@ -9,6 +9,27 @@ export default OakPage({
mobile: 1,
userId: 1,
},
filters: [{
filter: async ({ features }) => {
const tokenId = await features.token.getToken();
return {
user: {
id: {
$in: {
entity: 'token',
data: {
userId: 1,
},
filter: {
id: tokenId,
ableState: 'enabled',
}
}
}
},
};
},
}],
formData: async ({ data: mobiles }) => ({
mobiles,
}),

View File

@ -1,5 +0,0 @@
{
"navigationBarTitleText": "用户登录",
"usingComponents": {
}
}

View File

@ -1,16 +0,0 @@
/** index.wxss **/
@import "../../../config/styles/_base.less";
@import "../../../config/styles/_mixins.less";
page {
height: 100%;
}
.page-body {
height: 100%;
display: flex;
flex-direction: column;
align-items: stretch;
justify-content: flex-end;
// background-color: slategrey;
}

View File

@ -1,35 +0,0 @@
export default OakPage({
path: 'token:login',
entity: 'token',
projection: {
id: 1,
wechatUser: {
id: 1,
},
userId: 1,
playerId: 1,
},
isList: true,
formData: async ({ features }) => {
const tokenValue = await features.token.getToken();
if (tokenValue) {
return {
loggedIn: true,
};
}
return {
loggedIn: false,
};
},
methods: {
async onLoginClicked(options: WechatMiniprogram.Touch) {
const { code } = await wx.login();
const env = await wx.getSystemInfo();
await this.features.token.loginWechatMp();
},
onReturnClicked() {
this.navigateBack();
},
},
});

View File

@ -1,9 +0,0 @@
import React, { Component } from 'react';
export default function render() {
return (
<div>
react
</div>
);
}

View File

@ -1,13 +0,0 @@
<!-- index.wxml -->
<view class="page-body">
<block wx:if="{{!loggedIn}}">
<view class="g-cell">
<button class="g-btn g-btn-fullWidth" size="default" bindtap="onLoginClicked">登录</button>
</view>
</block>
<block wx:else>
<view class="g-cell">
<button class="g-btn g-btn-fullWidth" size="default" bindtap="onReturnClicked">返回</button>
</view>
</block>
</view>

View File

@ -55,9 +55,9 @@ export default OakPage({
},
filters: [{
filter: async ({ features }) => {
const token = await features.token.getToken();
const tokenId = await features.token.getToken();
return {
id: token,
id: tokenId,
};
},
}],
@ -109,13 +109,24 @@ export default OakPage({
refreshing: true,
});
try {
await this.features.token.loginWechatMp();
switch(process.env.OAK_PLATFORM) {
case 'wechatMp': {
await this.features.token.loginWechatMp();
this.setState({
refreshing: false,
});
break;
}
case 'web': {
this.navigateTo({
url: '/mobile/me'
});
break;
}
}
} catch (err) {
console.error(err);
}
this.setState({
refreshing: false,
});
},
goMyMobile() {
this.navigateTo({

View File

@ -1,13 +1,51 @@
import React, { Component } from 'react';
import { UserOutlined, RightOutlined } from '@ant-design/icons';
import { Avatar, Image, Button, List } from 'antd';
export default function render() {
const { avatar } = this.state;
const { avatar, nickname, isLoggedIn, refreshing, mobile, mobileCount } = this.state;
const mobileText = mobileCount > 1 ? `${mobileCount}条手机号` : ( mobile || '未设置');
return (
<div className='page-body'>
<div className='userInfo'>
{
avatar ?
avatar ? <Avatar src={<Image src={avatar} className="avatar" />} /> : <Avatar icon={<UserOutlined />} size={120} />
}
<span className="nickname">{nickname || '未设置'}</span>
{
isLoggedIn ?
<Button
size="small"
disabled={refreshing}
loading={refreshing}
onClick={() => this.onRefresh()}
>
</Button> :
<Button
size="small"
disabled={refreshing}
loading={refreshing}
onClick={() => this.doLogin()}
>
</Button>
}
</div>
<div className='cell'>
<List>
<List.Item style={{
marginLeft: 20,
marginRight: 20,
}}>
<List.Item.Meta
title="手机号"
description={mobileText}
onClick={() => console.log('aaa')}
/>
<RightOutlined />
</List.Item>
</List>
</div>
</div>
);

View File

@ -9,7 +9,7 @@ export declare function createWechatQrCode<ED extends EntityDict, T extends keyo
lifetimeLength?: number;
permanent?: boolean;
props: WechatQrCodeProps;
}, context: Cxt): Promise<Omit<Omit<import("general-app-domain/WechatQrCode/Schema").OpSchema, "applicationId" | "entity" | "entityId">, import("oak-domain/lib/types").InstinctiveAttributes> & {
}, context: Cxt): Promise<Omit<Omit<import("general-app-domain/WechatQrCode/Schema").OpSchema, "entity" | "entityId" | "applicationId">, import("oak-domain/lib/types").InstinctiveAttributes> & {
id: string;
} & {
applicationId: string;

View File

@ -12,10 +12,17 @@ const locale = {
user: '用户',
player: '扮演者',
env: '环境',
ableState: '状态',
},
action: {
enable: '激活',
disable: '禁用',
}
},
v: {
ableState: {
enabled: '使用中',
disabled: '已禁用'
},
},
},
};

View File

@ -57,6 +57,8 @@ const locale = {
idNumber: '证件号码',
ref: '介绍人',
files: '相关文件',
userState: '用户状态',
idState: '身份验证状态',
},
action: {
activate: '激活',

View File

@ -38,7 +38,8 @@ const locale = {
granter: '授权人',
files: '微信码',
expired: '是否过期',
expiresAt: '过期时间'
expiresAt: '过期时间',
iState: '状态',
},
action: {
confirm: '确认'

View File

@ -40,7 +40,7 @@
"prebuild": "ts-node ./scripts/make.ts",
"build": "tsc",
"get:area": "ts-node ./scripts/getAmapArea.ts",
"clean:dts": "ts-node ./scripts/cleanDtsAndJs"
"clean:dir": "ts-node ./scripts/cleanDtsAndJs"
},
"main": "src/index"
}

View File

@ -1,7 +1,7 @@
import { String, Int, Datetime, Image, Boolean } from 'oak-domain/lib/types/DataType';
import { Schema as User } from './User';
import { Schema as Application } from './Application';
import { AbleAction, makeAbleActionDef } from 'oak-domain/lib/actions/action';
import { AbleAction, AbleState, makeAbleActionDef } from 'oak-domain/lib/actions/action';
import { EntityShape } from 'oak-domain/lib/types/Entity';
import { LocaleDef } from 'oak-domain/lib/types/Locale';
// https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html
@ -48,7 +48,9 @@ type Action = AbleAction;
const AbleActionDef = makeAbleActionDef('enabled');
const locale: LocaleDef<Schema, Action, '', {}> = {
const locale: LocaleDef<Schema, Action, '', {
ableState: AbleState,
}> = {
zh_CN: {
attr: {
application: '应用',
@ -57,10 +59,17 @@ const locale: LocaleDef<Schema, Action, '', {}> = {
user: '用户',
player: '扮演者',
env: '环境',
ableState: '状态',
},
action: {
enable: '激活',
disable: '禁用',
}
},
v: {
ableState: {
enabled: '使用中',
disabled: '已禁用'
},
},
},
};

View File

@ -90,6 +90,8 @@ const locale: LocaleDef<Schema, Action, '', {
idNumber: '证件号码',
ref: '介绍人',
files: '相关文件',
userState: '用户状态',
idState: '身份验证状态',
},
action: {
activate: '激活',

View File

@ -65,7 +65,8 @@ const locale: LocaleDef<Schema, Action, '', {
granter: '授权人',
files: '微信码',
expired: '是否过期',
expiresAt: '过期时间'
expiresAt: '过期时间',
iState: '状态',
},
action: {
confirm: '确认'