This commit is contained in:
梁朝伟 2022-07-16 17:40:22 +08:00
commit 03497ff5ca
13 changed files with 82 additions and 36 deletions

View File

@ -5,7 +5,7 @@ interface TimedNotificationdata extends NotificationData {
dieAt: number;
};
let KILLER: number | undefined = undefined;
let KILLER: NodeJS.Timeout | undefined = undefined;
export default OakComponent({
data: {
messages: [] as TimedNotificationdata[],
@ -37,7 +37,7 @@ export default OakComponent({
}
}
if (typeof KILLER === 'number') {
if (KILLER) {
clearTimeout(KILLER);
}
KILLER = setTimeout(

View File

@ -30,7 +30,7 @@ export default OakPage({
}
else if (this.counterHandler) {
clearTimeout(this.couuterHandler);
this.counterHandler = undefined;
this.counterHandler = undefined;
}
}
return {
@ -40,33 +40,47 @@ export default OakPage({
methods: {
onInput(e: any) {
const { dataset, value } = this.resolveInput(e);
const{ attr } = dataset;
const { attr } = dataset;
this.setState({
[attr]: value,
});
},
async sendCaptcha() {
const { mobile } = this.state;
const result = await this.features.token.sendCaptcha(mobile);
// 显示返回消息
this.setState({
oakError: {
try {
const result = await this.features.token.sendCaptcha(mobile);
// 显示返回消息
this.setNotification({
type: 'success',
msg: result,
}
});
this.save(SEND_KEY, Date.now());
this.reRender();
content: result,
});
this.save(SEND_KEY, Date.now());
this.reRender();
}
catch (err) {
this.setNotification({
type: 'error',
content: (err as Error).message,
});
}
},
async loginByMobile() {
const { eventLoggedIn } = this.props;
const { mobile, password, captcha } = this.state;
await this.features.token.loginByMobile(mobile, password, captcha);
if (eventLoggedIn) {
this.pub(eventLoggedIn);
try {
await this.features.token.loginByMobile(mobile, password, captcha);
if (eventLoggedIn) {
this.pub(eventLoggedIn);
}
else {
this.navigateBack();
}
}
else {
this.navigateBack();
catch (err) {
this.setNotification({
type: 'error',
content: (err as Error).message,
});
}
}
},

40
lib/aspects/AspectDict.d.ts vendored Normal file
View File

@ -0,0 +1,40 @@
import { WebEnv, WechatMpEnv } from "general-app-domain/Token/Schema";
import { AppType } from 'general-app-domain/Application/Schema';
import { EntityDict } from "general-app-domain";
import { QiniuUploadInfo } from "oak-frontend-base/src/types/Upload";
import { GeneralRuntimeContext } from "../RuntimeContext";
declare type GeneralAspectDict<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>> = {
loginByMobile: (params: {
captcha?: string;
password?: string;
mobile: string;
env: WebEnv | WechatMpEnv;
}, context: Cxt) => Promise<string>;
loginMp: (params: {
code: string;
}, context: Cxt) => Promise<string>;
loginWechatMp: ({ code, env }: {
code: string;
env: WechatMpEnv;
}, context: Cxt) => Promise<string>;
syncUserInfoWechatMp: ({ nickname, avatarUrl, encryptedData, iv, signature }: {
nickname: string;
avatarUrl: string;
encryptedData: string;
iv: string;
signature: string;
}, context: Cxt) => Promise<void>;
getUploadInfo: (params: {
origin: string;
fileName: string;
}, context: Cxt) => Promise<QiniuUploadInfo>;
sendCaptcha: (params: {
mobile: string;
env: WechatMpEnv | WebEnv;
}) => Promise<string>;
getApplication: (params: {
type: AppType;
}, context: Cxt) => Promise<string>;
};
export declare type AspectDict<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>> = GeneralAspectDict<ED, Cxt>;
export {};

View File

@ -3,5 +3,4 @@ import { AppType } from "general-app-domain/Application/Schema";
import { GeneralRuntimeContext } from "../RuntimeContext";
export declare function getApplication<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: {
type: AppType;
url: string;
}, context: Cxt): Promise<string>;

View File

@ -24,7 +24,7 @@ export declare class Application<ED extends EntityDict, Cxt extends GeneralRunti
private rwLock;
private cache;
private storage;
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>, type: AppType, url: string, cache: Cache<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, storage: LocalStorage<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, callback: (application: SelectRowShape<ED['application']['Schema'], typeof projection>) => void);
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>, type: AppType, cache: Cache<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, storage: LocalStorage<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, callback: (application: SelectRowShape<ED['application']['Schema'], typeof projection>) => void);
private getApplicationFromCache;
private refresh;
getApplication(): Promise<SelectRowShape<ED["application"]["Schema"], {

View File

@ -25,7 +25,7 @@ class Application extends oak_frontend_base_1.Feature {
rwLock;
cache;
storage;
constructor(aspectWrapper, type, url, cache, storage, callback) {
constructor(aspectWrapper, type, cache, storage, callback) {
super(aspectWrapper);
this.rwLock = new concurrent_1.RWLock();
this.cache = cache;
@ -37,7 +37,7 @@ class Application extends oak_frontend_base_1.Feature {
this.getApplicationFromCache(callback);
}
else {
this.refresh(type, url, callback);
this.refresh(type, callback);
}
this.rwLock.release();
}
@ -52,9 +52,8 @@ class Application extends oak_frontend_base_1.Feature {
this.application = result[0];
callback(this.application);
}
async refresh(type, url, callback) {
async refresh(type, callback) {
const { result: applicationId } = await this.getAspectWrapper().exec('getApplication', {
url,
type,
});
this.applicationId = applicationId;

View File

@ -8,7 +8,7 @@ import { BasicFeatures } from 'oak-frontend-base';
import { AspectDict } from '../aspects/AspectDict';
import { AspectWrapper } from 'oak-domain/lib/types';
import { AppType } from 'general-app-domain/Application/Schema';
export declare function initialize<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>>(aspectWrapper: AspectWrapper<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, type: AppType, url: string, context: Cxt): {
export declare function initialize<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>>(aspectWrapper: AspectWrapper<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, type: AppType, context: Cxt): {
token: Token<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
extraFile: ExtraFile<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
application: Application<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;

View File

@ -4,8 +4,8 @@ exports.initialize = void 0;
const token_1 = require("./token");
const extraFile_1 = require("./extraFile");
const application_1 = require("./application");
function initialize(aspectWrapper, basicFeatures, type, url, context) {
const application = new application_1.Application(aspectWrapper, type, url, basicFeatures.cache, basicFeatures.localStorage, (application) => context.setApplication(application));
function initialize(aspectWrapper, basicFeatures, type, context) {
const application = new application_1.Application(aspectWrapper, type, basicFeatures.cache, basicFeatures.localStorage, (application) => context.setApplication(application));
const token = new token_1.Token(aspectWrapper, basicFeatures.cache, basicFeatures.localStorage, context);
const extraFile = new extraFile_1.ExtraFile(aspectWrapper);
return {

View File

@ -56,7 +56,6 @@
"get:area": "ts-node ./scripts/getAmapArea.ts",
"clean:dir": "ts-node ./scripts/cleanDtsAndJs",
"test": "ts-node ./test/test.ts",
"postinstall": "npm run prebuild",
"prepare": "rimraf node_modules/react & rimraf node_modules/react-dom & rimraf node_modules/react-router"
},
"main": "src/index"

View File

@ -22,7 +22,6 @@ type GeneralAspectDict<ED extends EntityDict, Cxt extends GeneralRuntimeContext<
}) => Promise<string>,
getApplication: (params: {
type: AppType;
url: string;
}, context: Cxt) => Promise<string>;
};

View File

@ -5,7 +5,6 @@ import { GeneralRuntimeContext } from "../RuntimeContext";
export async function getApplication<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: {
type: AppType;
url: string;
}, context: Cxt) {
const { type } = params;
const appId = type === 'web' ? DEV_WEB_APPLICATION_ID : DEV_WECHATMP_APPLICATION_ID;

View File

@ -44,7 +44,6 @@ export class Application<ED extends EntityDict, Cxt extends GeneralRuntimeContex
constructor(
aspectWrapper: AspectWrapper<ED, Cxt, AD>,
type: AppType,
url: string,
cache: Cache<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
storage: LocalStorage<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
callback: (application: SelectRowShape<ED['application']['Schema'], typeof projection>) => void) {
@ -59,7 +58,7 @@ export class Application<ED extends EntityDict, Cxt extends GeneralRuntimeContex
this.getApplicationFromCache(callback);
}
else {
this.refresh(type, url, callback);
this.refresh(type, callback);
}
this.rwLock.release();
}
@ -76,9 +75,8 @@ export class Application<ED extends EntityDict, Cxt extends GeneralRuntimeContex
callback(this.application!);
}
private async refresh(type: AppType, url: string, callback: (application: SelectRowShape<ED['application']['Schema'], typeof projection>) => void) {
private async refresh(type: AppType, callback: (application: SelectRowShape<ED['application']['Schema'], typeof projection>) => void) {
const { result: applicationId } = await this.getAspectWrapper().exec('getApplication', {
url,
type,
});
this.applicationId = applicationId;

View File

@ -13,11 +13,10 @@ export function initialize<ED extends EntityDict, Cxt extends GeneralRuntimeCont
aspectWrapper: AspectWrapper<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
type: AppType,
url: string,
context: Cxt,
) {
const application = new Application<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>(
aspectWrapper, type, url, basicFeatures.cache, basicFeatures.localStorage, (application) => context.setApplication(application));
aspectWrapper, type, basicFeatures.cache, basicFeatures.localStorage, (application) => context.setApplication(application));
const token = new Token<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>(aspectWrapper, basicFeatures.cache, basicFeatures.localStorage, context);
const extraFile = new ExtraFile<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>(aspectWrapper);
return {