框架的修改
This commit is contained in:
parent
c36b804d50
commit
26887d71e0
|
|
@ -5,9 +5,11 @@ export declare abstract class GeneralRuntimeContext<ED extends EntityDict> exten
|
||||||
applicationId: string;
|
applicationId: string;
|
||||||
token?: string;
|
token?: string;
|
||||||
constructor(store: RowStore<ED, GeneralRuntimeContext<ED>>, appId: string, token?: string);
|
constructor(store: RowStore<ED, GeneralRuntimeContext<ED>>, appId: string, token?: string);
|
||||||
getApplication(): Promise<import("oak-domain/lib/types").SelectRowShape<ED["application"]["Schema"], {
|
getApplication(): Promise<import("oak-domain/lib/types").SelectRowShape<import("oak-app-domain/Application/Schema").Schema, {
|
||||||
id: 1;
|
id: 1;
|
||||||
name: 1;
|
name: 1;
|
||||||
|
config: 1;
|
||||||
|
type: 1;
|
||||||
}>>;
|
}>>;
|
||||||
getToken(): Promise<import("oak-domain/lib/types").SelectRowShape<ED["token"]["Schema"], {
|
getToken(): Promise<import("oak-domain/lib/types").SelectRowShape<ED["token"]["Schema"], {
|
||||||
id: 1;
|
id: 1;
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,15 @@ class GeneralRuntimeContext extends UniversalContext_1.UniversalContext {
|
||||||
data: {
|
data: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 1,
|
name: 1,
|
||||||
|
config: 1,
|
||||||
|
type: 1,
|
||||||
},
|
},
|
||||||
filter: {
|
filter: {
|
||||||
id: this.applicationId,
|
id: this.applicationId,
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
application.type;
|
||||||
|
const t = 'type';
|
||||||
return application;
|
return application;
|
||||||
}
|
}
|
||||||
async getToken() {
|
async getToken() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { loginByPassword, loginMp } from './token';
|
import { loginByPassword, loginMp, loginWechatMp } from './token';
|
||||||
export declare const aspectDict: {
|
export declare const aspectDict: {
|
||||||
loginByPassword: typeof loginByPassword;
|
loginByPassword: typeof loginByPassword;
|
||||||
loginMp: typeof loginMp;
|
loginMp: typeof loginMp;
|
||||||
|
loginWechatMp: typeof loginWechatMp;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ const token_1 = require("./token");
|
||||||
exports.aspectDict = {
|
exports.aspectDict = {
|
||||||
loginByPassword: token_1.loginByPassword,
|
loginByPassword: token_1.loginByPassword,
|
||||||
loginMp: token_1.loginMp,
|
loginMp: token_1.loginMp,
|
||||||
|
loginWechatMp: token_1.loginWechatMp,
|
||||||
};
|
};
|
||||||
// export type AspectDict<ED extends EntityDict & BaseEntityDict> = TokenAD<ED> & CrudAD<ED>;
|
// export type AspectDict<ED extends EntityDict & BaseEntityDict> = TokenAD<ED> & CrudAD<ED>;
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,4 @@ export declare function loginByPassword<ED extends EntityDict, Cxt extends Gener
|
||||||
password: string;
|
password: string;
|
||||||
mobile: string;
|
mobile: string;
|
||||||
}, context: Cxt): Promise<string>;
|
}, context: Cxt): Promise<string>;
|
||||||
|
export declare function loginWechatMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(code: string, context: Cxt): Promise<string>;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.loginByPassword = exports.loginMp = void 0;
|
exports.loginWechatMp = exports.loginByPassword = exports.loginMp = void 0;
|
||||||
|
const assert_1 = __importDefault(require("assert"));
|
||||||
async function loginMp(params, context) {
|
async function loginMp(params, context) {
|
||||||
const { rowStore } = context;
|
const { rowStore } = context;
|
||||||
throw new Error('method not implemented!');
|
throw new Error('method not implemented!');
|
||||||
|
|
@ -18,6 +22,14 @@ async function loginByPassword(params, context) {
|
||||||
throw new Error('method not implemented!');
|
throw new Error('method not implemented!');
|
||||||
}
|
}
|
||||||
exports.loginByPassword = loginByPassword;
|
exports.loginByPassword = loginByPassword;
|
||||||
|
async function loginWechatMp(code, context) {
|
||||||
|
const application = await context.getApplication();
|
||||||
|
const { type, config } = application;
|
||||||
|
(0, assert_1.default)(type === 'wechatMp' || config.type === 'wechatMp');
|
||||||
|
const config2 = config;
|
||||||
|
new Error('method not implemented!');
|
||||||
|
}
|
||||||
|
exports.loginWechatMp = loginWechatMp;
|
||||||
/* export type AspectDict<ED extends EntityDict> = {
|
/* export type AspectDict<ED extends EntityDict> = {
|
||||||
loginMp: (params: { code: string }, context: GeneralRuntimeContext<ED>) => Promise<string>;
|
loginMp: (params: { code: string }, context: GeneralRuntimeContext<ED>) => Promise<string>;
|
||||||
loginByPassword: (params: { password: string, mobile: string }, context: GeneralRuntimeContext<ED>) => Promise<string>;
|
loginByPassword: (params: { password: string, mobile: string }, context: GeneralRuntimeContext<ED>) => Promise<string>;
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,16 @@ import { String, Text } from 'oak-domain/lib/types/DataType';
|
||||||
import { EntityShape } from 'oak-domain/lib/types/Entity';
|
import { EntityShape } from 'oak-domain/lib/types/Entity';
|
||||||
import { Schema as System } from './System';
|
import { Schema as System } from './System';
|
||||||
import { Schema as ExtraFile } from './ExtraFile';
|
import { Schema as ExtraFile } from './ExtraFile';
|
||||||
declare type WechatMpConfig = {
|
export declare type WechatMpConfig = {
|
||||||
type: 'wechatMp';
|
type: 'wechatMp';
|
||||||
appId: string;
|
appId: string;
|
||||||
appSecret: string;
|
appSecret: string;
|
||||||
};
|
};
|
||||||
declare type WebConfig = {
|
export declare type WebConfig = {
|
||||||
type: 'web';
|
type: 'web';
|
||||||
domain: string;
|
domain: string;
|
||||||
};
|
};
|
||||||
declare type WechatPublicCofig = {
|
export declare type WechatPublicCofig = {
|
||||||
type: 'wechatPublic';
|
type: 'wechatPublic';
|
||||||
appId: string;
|
appId: string;
|
||||||
appSecret: string;
|
appSecret: string;
|
||||||
|
|
@ -19,9 +19,8 @@ declare type WechatPublicCofig = {
|
||||||
export interface Schema extends EntityShape {
|
export interface Schema extends EntityShape {
|
||||||
name: String<32>;
|
name: String<32>;
|
||||||
description: Text;
|
description: Text;
|
||||||
type: 'web' | 'wechatPublic' | 'weChatMp';
|
type: 'web' | 'wechatPublic' | 'wechatMp';
|
||||||
system: System;
|
system: System;
|
||||||
dd: Array<ExtraFile>;
|
dd: Array<ExtraFile>;
|
||||||
config: WebConfig | WechatMpConfig | WechatPublicCofig;
|
config: WebConfig | WechatMpConfig | WechatPublicCofig;
|
||||||
}
|
}
|
||||||
export {};
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
|
import { EntityDict } from 'oak-app-domain';
|
||||||
|
import { Aspect, Context } from 'oak-domain/lib/types';
|
||||||
import { Token } from './token';
|
import { Token } from './token';
|
||||||
export declare function initialize(): {
|
export declare function initialize<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>>(): {
|
||||||
token: Token;
|
token: Token<ED, Cxt, AD>;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { EntityDict } from 'oak-app-domain';
|
import { EntityDict } from 'oak-app-domain';
|
||||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
|
||||||
import { aspectDict } from '../aspects';
|
|
||||||
import { Feature } from 'oak-frontend-base';
|
import { Feature } from 'oak-frontend-base';
|
||||||
export declare class Token extends Feature<EntityDict, GeneralRuntimeContext<EntityDict>, typeof aspectDict> {
|
import { Aspect, Context } from 'oak-domain/lib/types';
|
||||||
|
export declare class Token<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>> extends Feature<ED, Cxt, AD> {
|
||||||
private token?;
|
private token?;
|
||||||
loginByPassword(mobile: string, password: string): Promise<void>;
|
loginByPassword(mobile: string, password: string): Promise<void>;
|
||||||
|
loginWechatMp(code: string): Promise<void>;
|
||||||
logout(): Promise<void>;
|
logout(): Promise<void>;
|
||||||
getToken(): string | undefined;
|
getToken(): string | undefined;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ class Token extends oak_frontend_base_1.Feature {
|
||||||
async loginByPassword(mobile, password) {
|
async loginByPassword(mobile, password) {
|
||||||
this.token = await this.getAspectProxy().loginByPassword({ password, mobile });
|
this.token = await this.getAspectProxy().loginByPassword({ password, mobile });
|
||||||
}
|
}
|
||||||
|
async loginWechatMp(code) {
|
||||||
|
this.token = await this.getAspectProxy().loginWechatMp(code);
|
||||||
|
}
|
||||||
async logout() {
|
async logout() {
|
||||||
this.token = undefined;
|
this.token = undefined;
|
||||||
}
|
}
|
||||||
|
|
@ -23,6 +26,9 @@ class Token extends oak_frontend_base_1.Feature {
|
||||||
__decorate([
|
__decorate([
|
||||||
oak_frontend_base_1.Action
|
oak_frontend_base_1.Action
|
||||||
], Token.prototype, "loginByPassword", null);
|
], Token.prototype, "loginByPassword", null);
|
||||||
|
__decorate([
|
||||||
|
oak_frontend_base_1.Action
|
||||||
|
], Token.prototype, "loginWechatMp", null);
|
||||||
__decorate([
|
__decorate([
|
||||||
oak_frontend_base_1.Action
|
oak_frontend_base_1.Action
|
||||||
], Token.prototype, "logout", null);
|
], Token.prototype, "logout", null);
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,13 @@ export abstract class GeneralRuntimeContext<ED extends EntityDict> extends Unive
|
||||||
data: {
|
data: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 1,
|
name: 1,
|
||||||
|
config: 1,
|
||||||
|
type: 1,
|
||||||
},
|
},
|
||||||
filter: {
|
filter: {
|
||||||
id: this.applicationId,
|
id: this.applicationId,
|
||||||
}
|
}
|
||||||
}, this) as SelectionResult<ED['application']['Schema'], {id: 1, name: 1}>;
|
}, this) as SelectionResult<EntityDict['application']['Schema'], {id: 1, name: 1, config: 1, type: 1}>;
|
||||||
|
|
||||||
return application;
|
return application;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||||
import { EntityDict } from 'oak-app-domain/EntityDict';
|
import { EntityDict } from 'oak-app-domain/EntityDict';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { WechatMpConfig } from 'oak-app-domain/Application/Schema';
|
||||||
|
|
||||||
export async function loginMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: { code: string }, context: Cxt): Promise<string> {
|
export async function loginMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: { code: string }, context: Cxt): Promise<string> {
|
||||||
const { rowStore } = context;
|
const { rowStore } = context;
|
||||||
|
|
@ -21,6 +23,17 @@ export async function loginByPassword<ED extends EntityDict, Cxt extends General
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loginWechatMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(code: string, context: Cxt): Promise<string> {
|
export async function loginWechatMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(code: string, context: Cxt): Promise<string> {
|
||||||
|
const application = await context.getApplication();
|
||||||
|
const { type, config } = application;
|
||||||
|
|
||||||
|
assert (type === 'wechatMp' || config.type === 'wechatMp');
|
||||||
|
const config2 = config as WechatMpConfig;
|
||||||
|
const { appId, appSecret } = config2;
|
||||||
|
|
||||||
|
const result = await fetch(`https://api.weixin.qq.com/sns/jscode2session?appid=${appId}&secret=${appSecret}&js_code=${code}&grant_type=authorization_code`);
|
||||||
|
const json = await result.json();
|
||||||
|
console.log(json);
|
||||||
|
|
||||||
throw new Error('method not implemented!');
|
throw new Error('method not implemented!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,18 @@ import { EntityShape } from 'oak-domain/lib/types/Entity';
|
||||||
import { Schema as System } from './System';
|
import { Schema as System } from './System';
|
||||||
import { Schema as ExtraFile } from './ExtraFile';
|
import { Schema as ExtraFile } from './ExtraFile';
|
||||||
|
|
||||||
type WechatMpConfig = {
|
export type WechatMpConfig = {
|
||||||
type: 'wechatMp';
|
type: 'wechatMp';
|
||||||
appId: string;
|
appId: string;
|
||||||
appSecret: string;
|
appSecret: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type WebConfig = {
|
export type WebConfig = {
|
||||||
type: 'web';
|
type: 'web';
|
||||||
domain: string;
|
domain: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type WechatPublicCofig = {
|
export type WechatPublicCofig = {
|
||||||
type: 'wechatPublic';
|
type: 'wechatPublic';
|
||||||
appId: string;
|
appId: string;
|
||||||
appSecret: string;
|
appSecret: string;
|
||||||
|
|
@ -23,7 +23,7 @@ type WechatPublicCofig = {
|
||||||
export interface Schema extends EntityShape {
|
export interface Schema extends EntityShape {
|
||||||
name: String<32>;
|
name: String<32>;
|
||||||
description: Text;
|
description: Text;
|
||||||
type: 'web' | 'wechatPublic' | 'weChatMp';
|
type: 'web' | 'wechatPublic' | 'wechatMp';
|
||||||
system: System;
|
system: System;
|
||||||
dd: Array<ExtraFile>;
|
dd: Array<ExtraFile>;
|
||||||
config: WebConfig | WechatMpConfig| WechatPublicCofig;
|
config: WebConfig | WechatMpConfig| WechatPublicCofig;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
|
import { EntityDict } from 'oak-app-domain';
|
||||||
|
import { Aspect, Context } from 'oak-domain/lib/types';
|
||||||
import { Token } from './token';
|
import { Token } from './token';
|
||||||
|
|
||||||
export function initialize() {
|
export function initialize<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>>() {
|
||||||
const token = new Token();
|
const token = new Token<ED, Cxt, AD>();
|
||||||
return {
|
return {
|
||||||
token,
|
token,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import { EntityDict } from 'oak-app-domain';
|
import { EntityDict } from 'oak-app-domain';
|
||||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
|
||||||
import { aspectDict } from '../aspects';
|
|
||||||
import { Action, Feature } from 'oak-frontend-base';
|
import { Action, Feature } from 'oak-frontend-base';
|
||||||
|
import { Aspect, Context } from 'oak-domain/lib/types';
|
||||||
|
|
||||||
export class Token extends Feature<EntityDict, GeneralRuntimeContext<EntityDict>, typeof aspectDict> {
|
export class Token<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>> extends Feature<ED, Cxt, AD> {
|
||||||
|
|
||||||
private token?: string;
|
private token?: string;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,8 @@
|
||||||
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"esnext",
|
||||||
"dom.iterable",
|
"DOM"
|
||||||
"esnext"
|
|
||||||
],
|
],
|
||||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
|
|
@ -65,9 +64,9 @@
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"resolveJsonModule": true, /* Disallow inconsistently-cased references to the same file. */
|
"resolveJsonModule": true, /* Disallow inconsistently-cased references to the same file. */
|
||||||
"typeRoots": [
|
"types": [
|
||||||
"./node_modules/@types",
|
"node",
|
||||||
"./node_modules/miniprogram-api-typings"
|
"miniprogram-api-typings"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"include": [ "./**/*.ts" ],
|
"include": [ "./**/*.ts" ],
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,15 @@
|
||||||
/** index.wxss **/
|
/** index.wxss **/
|
||||||
@import "../../../styles/base.less";
|
@import "../../../styles/base.less";
|
||||||
@import "../../../styles/cpn.less";
|
@import "../../../styles/cpn.less";
|
||||||
|
page {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.page-body {
|
.page-body {
|
||||||
|
height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
background-color: slategrey;
|
justify-content: flex-end;
|
||||||
|
// background-color: slategrey;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,11 @@ OakPage({
|
||||||
entity: 'token',
|
entity: 'token',
|
||||||
projection: {
|
projection: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 1,
|
wechatUser: {
|
||||||
depth: 1,
|
id: 1,
|
||||||
level: 1,
|
},
|
||||||
|
userId: 1,
|
||||||
|
playerId: 1,
|
||||||
},
|
},
|
||||||
isList: true,
|
isList: true,
|
||||||
formData: (tokenList, features) => {
|
formData: (tokenList, features) => {
|
||||||
|
|
@ -23,8 +25,8 @@ OakPage({
|
||||||
}, {
|
}, {
|
||||||
methods: {
|
methods: {
|
||||||
async onLoginClicked(options: WechatMiniprogram.Touch) {
|
async onLoginClicked(options: WechatMiniprogram.Touch) {
|
||||||
const code = await wx.login();
|
const { code } = await wx.login();
|
||||||
console.log(code);
|
await this.features.token.loginWechatMp(code);
|
||||||
},
|
},
|
||||||
|
|
||||||
onReturnClicked() {
|
onReturnClicked() {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<!-- index.wxml -->
|
<!-- index.wxml -->
|
||||||
<view class="page-body">
|
<view class="page-body">
|
||||||
<block wx:if={{loggedIn}}>
|
<block wx:if={{!loggedIn}}>
|
||||||
<view class="g-cell">
|
<view class="g-cell">
|
||||||
<button class="g-btn g-btn-fullWidth" size="default" bindtap="onLoginClicked">登录</button>
|
<button class="g-btn g-btn-fullWidth" size="default" bindtap="onLoginClicked">登录</button>
|
||||||
</view>
|
</view>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue