logingwechat 增加 wechatloginid参数

This commit is contained in:
Wang Kejun 2023-05-10 12:18:15 +08:00
parent 4f73b42ca2
commit 75c517cc3c
10 changed files with 137 additions and 15 deletions

View File

@ -20,9 +20,10 @@ declare type GeneralAspectDict<ED extends EntityDict, Cxt extends BackendRuntime
mobile: string; mobile: string;
env: WebEnv | WechatMpEnv; env: WebEnv | WechatMpEnv;
}, context: Cxt) => Promise<string>; }, context: Cxt) => Promise<string>;
loginWechat: ({ code, env, }: { loginWechat: ({ code, env, wechatLoginId, }: {
code: string; code: string;
env: WebEnv; env: WebEnv;
wechatLoginId?: string;
}, context: Cxt) => Promise<string>; }, context: Cxt) => Promise<string>;
logout: ({}: {}, context: Cxt) => Promise<void>; logout: ({}: {}, context: Cxt) => Promise<void>;
loginWechatMp: ({ code, env, }: { loginWechatMp: ({ code, env, }: {

View File

@ -136,17 +136,18 @@ var Token = /** @class */ (function (_super) {
}); });
}; };
Token.prototype.logout = function () { Token.prototype.logout = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () { // return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) { // return tslib_1.__generator(this, function (_a) {
switch (_a.label) { // switch (_a.label) {
case 0: return [4 /*yield*/, this.cache.exec('logout', {})]; // case 0: return [4 /*yield*/, this.cache.exec('logout', {})];
case 1: // case 1:
_a.sent(); // _a.sent();
this.removeToken(); // this.removeToken();
return [2 /*return*/]; // return [2 /*return*/];
} // }
}); // });
}); // });
this.removeToken();
}; };
Token.prototype.removeToken = function () { Token.prototype.removeToken = function () {
this.tokenValue = undefined; this.tokenValue = undefined;

View File

@ -0,0 +1,5 @@
/// <reference types="wechat-miniprogram" />
/// <reference types="react" />
import { EntityDict } from '../../../general-app-domain';
declare const _default: (props: import("oak-frontend-base").ReactComponentProps<EntityDict, "wechatLogin", false, WechatMiniprogram.Component.DataOption>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
export default _default;

View File

@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = OakComponent({
entity: 'wechatLogin',
projection: {
id: 1,
expired: 1,
expiresAt: 1,
userId: 1,
type: 1,
qrCodeType: 1,
successed: 1,
},
isList: false,
formData: function (_a) {
var wechatLogin = _a.data, features = _a.features;
var loginUserId = features.token.getUserId(true);
var user = wechatLogin === null || wechatLogin === void 0 ? void 0 : wechatLogin.user;
var userId = wechatLogin === null || wechatLogin === void 0 ? void 0 : wechatLogin.userId;
var type = wechatLogin === null || wechatLogin === void 0 ? void 0 : wechatLogin.type;
return {
type: type,
userId: userId,
expired: wechatLogin === null || wechatLogin === void 0 ? void 0 : wechatLogin.expired,
expiresAt: wechatLogin === null || wechatLogin === void 0 ? void 0 : wechatLogin.expiresAt,
successed: wechatLogin === null || wechatLogin === void 0 ? void 0 : wechatLogin.successed,
loginUserId: loginUserId,
};
},
listeners: {},
methods: {},
});

View File

@ -0,0 +1,7 @@
{
"navigationBarTitleText": "绑定/登录",
"usingComponents": {
"l-icon": "@oak-frontend-base/miniprogram_npm/lin-ui/icon/index",
"l-button": "@oak-frontend-base/miniprogram_npm/lin-ui/button/index"
}
}

16
lib/pages/wechatLogin/confirm/web.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
import { WebComponentProps } from 'oak-frontend-base';
import { EntityDict } from '../../../general-app-domain';
export default function Render(props: WebComponentProps<EntityDict, 'wechatLogin', true, {
type: EntityDict['wechatLogin']['Schema']['type'];
expired: boolean;
expiresAt: boolean;
user?: {
name: string;
nickname: string;
};
successed: number;
userId: string;
loginUserId: string;
}, {
handleConfirm: () => void;
}>): JSX.Element;

View File

@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var antd_1 = require("antd");
var web_module_less_1 = tslib_1.__importDefault(require("./web.module.less"));
var utils_1 = require("oak-frontend-base/lib/utils/utils");
function Render(props) {
var _a = props.data, oakLoading = _a.oakLoading, oakExecuting = _a.oakExecuting, type = _a.type, expired = _a.expired, expiresAt = _a.expiresAt, user = _a.user, successed = _a.successed, userId = _a.userId, loginUserId = _a.loginUserId;
var _b = props.methods, t = _b.t, handleConfirm = _b.handleConfirm;
var V;
if (successed) {
V = '成功的';
}
else if (expired) {
V = '过期了';
}
return ((0, jsx_runtime_1.jsxs)("div", tslib_1.__assign({ className: web_module_less_1.default.container }, { children: [(0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: web_module_less_1.default.content }, { children: V })), (0, jsx_runtime_1.jsxs)(antd_1.Space, tslib_1.__assign({ direction: "vertical" }, { children: [!oakLoading && !expired && !successed && ((0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({ size: "large", block: true, type: "primary", onClick: function () {
handleConfirm();
}, disabled: oakExecuting }, { children: "\u9886\u53D6" }))), utils_1.isWeiXin && ((0, jsx_runtime_1.jsx)(antd_1.Button, tslib_1.__assign({ size: "large", block: true, onClick: function () {
WeixinJSBridge.call('closeWindow');
} }, { children: "\u5173\u95ED" })))] }))] })));
}
exports.default = Render;

View File

@ -34,9 +34,11 @@ type GeneralAspectDict<
{ {
code, code,
env, env,
wechatLoginId,
}: { }: {
code: string; code: string;
env: WebEnv; env: WebEnv;
wechatLoginId?: string;
}, },
context: Cxt context: Cxt
) => Promise<string>; ) => Promise<string>;

View File

@ -56,11 +56,12 @@ export class Token<
this.publish(); this.publish();
} }
async loginWechat(code: string) { async loginWechat(code: string, params?: { wechatLoginId: string }) {
const env = await getEnv(); const env = await getEnv();
const { result } = await this.cache.exec('loginWechat', { const { result } = await this.cache.exec('loginWechat', {
code, code,
env: env as WebEnv, env: env as WebEnv,
wechatLoginId: params?.wechatLoginId,
}); });
this.tokenValue = result; this.tokenValue = result;
this.storage.save('token:token', result); this.storage.save('token:token', result);
@ -103,7 +104,7 @@ export class Token<
} }
async logout() { async logout() {
await this.cache.exec('logout', {}); // await this.cache.exec('logout', {});
this.removeToken(); this.removeToken();
} }

View File

@ -16,6 +16,7 @@ import { EntityDict } from '../../../general-app-domain';
import PageHeader from '../../../components/common/pageHeader'; import PageHeader from '../../../components/common/pageHeader';
import OakAvatar from '../../../components/extraFile/avatar'; import OakAvatar from '../../../components/extraFile/avatar';
import MobileLogin from '../../../pages/mobile/login'; import MobileLogin from '../../../pages/mobile/login';
// import WechatLoginQrCode from '../../../components/wechatLogin/qrCode';
import Style from './web.module.less'; import Style from './web.module.less';
@ -59,9 +60,10 @@ export default function Render(
oakDirty, oakDirty,
} = data; } = data;
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [open2, setOpen2] = useState(false);
return ( return (
<PageHeader title="修改个人信息" showBack={showBack}> <PageHeader title="个人设置" showBack={showBack}>
<div className={Style.container}> <div className={Style.container}>
<Form <Form
labelCol={{ xs: { span: 4 }, md: { span: 6 } }} labelCol={{ xs: { span: 4 }, md: { span: 6 } }}
@ -191,6 +193,21 @@ export default function Render(
</Space> </Space>
</> </>
</Form.Item> </Form.Item>
{/* <Form.Item label="">
<>
<Space>
<Typography>{mobile || '未设置'}</Typography>
<Button
size="small"
onClick={() => {
setOpen2(true);
}}
>
</Button>
</Space>
</>
</Form.Item> */}
<Form.Item <Form.Item
wrapperCol={{ wrapperCol={{
xs: { offset: 4 }, xs: { offset: 4 },
@ -228,6 +245,22 @@ export default function Render(
oakAutoUnmount={true} oakAutoUnmount={true}
/> />
</Modal> </Modal>
{/*
<Modal
title="绑定微信"
open={open2}
destroyOnClose={true}
footer={null}
maskClosable={false}
onCancel={() => {
setOpen2(false);
}}
>
<WechatLoginQrCode
oakPath="$user/info-wechatLogin/qrCode"
oakAutoUnmount={true}
/>
</Modal> */}
</PageHeader> </PageHeader>
); );
} }