框架的修改

This commit is contained in:
Xu Chang 2022-04-28 11:07:39 +08:00
parent c36b804d50
commit 26887d71e0
19 changed files with 86 additions and 36 deletions

View File

@ -5,9 +5,11 @@ export declare abstract class GeneralRuntimeContext<ED extends EntityDict> exten
applicationId: 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;
name: 1;
config: 1;
type: 1;
}>>;
getToken(): Promise<import("oak-domain/lib/types").SelectRowShape<ED["token"]["Schema"], {
id: 1;

View File

@ -15,11 +15,15 @@ class GeneralRuntimeContext extends UniversalContext_1.UniversalContext {
data: {
id: 1,
name: 1,
config: 1,
type: 1,
},
filter: {
id: this.applicationId,
}
}, this);
application.type;
const t = 'type';
return application;
}
async getToken() {

View File

@ -1,5 +1,6 @@
import { loginByPassword, loginMp } from './token';
import { loginByPassword, loginMp, loginWechatMp } from './token';
export declare const aspectDict: {
loginByPassword: typeof loginByPassword;
loginMp: typeof loginMp;
loginWechatMp: typeof loginWechatMp;
};

View File

@ -5,5 +5,6 @@ const token_1 = require("./token");
exports.aspectDict = {
loginByPassword: token_1.loginByPassword,
loginMp: token_1.loginMp,
loginWechatMp: token_1.loginWechatMp,
};
// export type AspectDict<ED extends EntityDict & BaseEntityDict> = TokenAD<ED> & CrudAD<ED>;

View File

@ -7,3 +7,4 @@ export declare function loginByPassword<ED extends EntityDict, Cxt extends Gener
password: string;
mobile: string;
}, context: Cxt): Promise<string>;
export declare function loginWechatMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(code: string, context: Cxt): Promise<string>;

View File

@ -1,6 +1,10 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
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) {
const { rowStore } = context;
throw new Error('method not implemented!');
@ -18,6 +22,14 @@ async function loginByPassword(params, context) {
throw new Error('method not implemented!');
}
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> = {
loginMp: (params: { code: string }, context: GeneralRuntimeContext<ED>) => Promise<string>;
loginByPassword: (params: { password: string, mobile: string }, context: GeneralRuntimeContext<ED>) => Promise<string>;

View File

@ -2,16 +2,16 @@ import { String, Text } from 'oak-domain/lib/types/DataType';
import { EntityShape } from 'oak-domain/lib/types/Entity';
import { Schema as System } from './System';
import { Schema as ExtraFile } from './ExtraFile';
declare type WechatMpConfig = {
export declare type WechatMpConfig = {
type: 'wechatMp';
appId: string;
appSecret: string;
};
declare type WebConfig = {
export declare type WebConfig = {
type: 'web';
domain: string;
};
declare type WechatPublicCofig = {
export declare type WechatPublicCofig = {
type: 'wechatPublic';
appId: string;
appSecret: string;
@ -19,9 +19,8 @@ declare type WechatPublicCofig = {
export interface Schema extends EntityShape {
name: String<32>;
description: Text;
type: 'web' | 'wechatPublic' | 'weChatMp';
type: 'web' | 'wechatPublic' | 'wechatMp';
system: System;
dd: Array<ExtraFile>;
config: WebConfig | WechatMpConfig | WechatPublicCofig;
}
export {};

View File

@ -1,4 +1,6 @@
import { EntityDict } from 'oak-app-domain';
import { Aspect, Context } from 'oak-domain/lib/types';
import { Token } from './token';
export declare function initialize(): {
token: Token;
export declare function initialize<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>>(): {
token: Token<ED, Cxt, AD>;
};

View File

@ -1,10 +1,10 @@
import { EntityDict } from 'oak-app-domain';
import { GeneralRuntimeContext } from '../RuntimeContext';
import { aspectDict } from '../aspects';
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?;
loginByPassword(mobile: string, password: string): Promise<void>;
loginWechatMp(code: string): Promise<void>;
logout(): Promise<void>;
getToken(): string | undefined;
}

View File

@ -13,6 +13,9 @@ class Token extends oak_frontend_base_1.Feature {
async loginByPassword(mobile, password) {
this.token = await this.getAspectProxy().loginByPassword({ password, mobile });
}
async loginWechatMp(code) {
this.token = await this.getAspectProxy().loginWechatMp(code);
}
async logout() {
this.token = undefined;
}
@ -23,6 +26,9 @@ class Token extends oak_frontend_base_1.Feature {
__decorate([
oak_frontend_base_1.Action
], Token.prototype, "loginByPassword", null);
__decorate([
oak_frontend_base_1.Action
], Token.prototype, "loginWechatMp", null);
__decorate([
oak_frontend_base_1.Action
], Token.prototype, "logout", null);

View File

@ -19,11 +19,13 @@ export abstract class GeneralRuntimeContext<ED extends EntityDict> extends Unive
data: {
id: 1,
name: 1,
config: 1,
type: 1,
},
filter: {
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;
}

View File

@ -1,5 +1,7 @@
import { GeneralRuntimeContext } from '../RuntimeContext';
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> {
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> {
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!');
}

View File

@ -3,18 +3,18 @@ import { EntityShape } from 'oak-domain/lib/types/Entity';
import { Schema as System } from './System';
import { Schema as ExtraFile } from './ExtraFile';
type WechatMpConfig = {
export type WechatMpConfig = {
type: 'wechatMp';
appId: string;
appSecret: string;
};
type WebConfig = {
export type WebConfig = {
type: 'web';
domain: string;
};
type WechatPublicCofig = {
export type WechatPublicCofig = {
type: 'wechatPublic';
appId: string;
appSecret: string;
@ -23,7 +23,7 @@ type WechatPublicCofig = {
export interface Schema extends EntityShape {
name: String<32>;
description: Text;
type: 'web' | 'wechatPublic' | 'weChatMp';
type: 'web' | 'wechatPublic' | 'wechatMp';
system: System;
dd: Array<ExtraFile>;
config: WebConfig | WechatMpConfig| WechatPublicCofig;

View File

@ -1,7 +1,9 @@
import { EntityDict } from 'oak-app-domain';
import { Aspect, Context } from 'oak-domain/lib/types';
import { Token } from './token';
export function initialize() {
const token = new Token();
export function initialize<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>>() {
const token = new Token<ED, Cxt, AD>();
return {
token,
};

View File

@ -1,9 +1,8 @@
import { EntityDict } from 'oak-app-domain';
import { GeneralRuntimeContext } from '../RuntimeContext';
import { aspectDict } from '../aspects';
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;

View File

@ -6,9 +6,8 @@
"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'. */
"lib": [
"dom",
"dom.iterable",
"esnext"
"esnext",
"DOM"
],
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
@ -65,9 +64,9 @@
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true, /* Disallow inconsistently-cased references to the same file. */
"typeRoots": [
"./node_modules/@types",
"./node_modules/miniprogram-api-typings"
"types": [
"node",
"miniprogram-api-typings"
]
},
"include": [ "./**/*.ts" ],

View File

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

View File

@ -4,9 +4,11 @@ OakPage({
entity: 'token',
projection: {
id: 1,
name: 1,
depth: 1,
level: 1,
wechatUser: {
id: 1,
},
userId: 1,
playerId: 1,
},
isList: true,
formData: (tokenList, features) => {
@ -23,8 +25,8 @@ OakPage({
}, {
methods: {
async onLoginClicked(options: WechatMiniprogram.Touch) {
const code = await wx.login();
console.log(code);
const { code } = await wx.login();
await this.features.token.loginWechatMp(code);
},
onReturnClicked() {

View File

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