From b80d3b92d58d2277b8b12819dad74ea2db35ebf3 Mon Sep 17 00:00:00 2001 From: Xc Date: Thu, 19 May 2022 22:53:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=BA=86=E5=90=AF=E5=8A=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/src/initialize.ts | 32 +++++++++++++++++++++ template/wechatMp/src/init.ts | 27 ++++-------------- template/wechatMp/src/utils/polyfill.ts | 38 ++++++++++++------------- 3 files changed, 56 insertions(+), 41 deletions(-) create mode 100644 template/src/initialize.ts diff --git a/template/src/initialize.ts b/template/src/initialize.ts new file mode 100644 index 0000000..dcf16a3 --- /dev/null +++ b/template/src/initialize.ts @@ -0,0 +1,32 @@ +import './utils/polyfill'; +import { initializeFeatures as initializeGeneralFeatures } from 'oak-general-business'; +import { BasicFeatures, } from 'oak-frontend-base'; +import { EntityDict } from 'oak-app-domain'; +import { RuntimeContext } from './RuntimeContext'; +import { aspectDict } from './aspects'; +import { initialize } from './features'; +import { checkers } from './checkers'; +import { triggers } from './triggers'; +import { data } from './data'; +import { routers } from './exceptionRouters'; + +const { token } = initializeGeneralFeatures(); + +const createFeatures = (basicFeatures: BasicFeatures) => { + const features = initialize(basicFeatures); + const wholeFeatures = Object.assign({ + token, + }, features); + return wholeFeatures; +}; + +export { + createFeatures, + aspectDict, + triggers, + checkers, + data, + routers, + + token, +} diff --git a/template/wechatMp/src/init.ts b/template/wechatMp/src/init.ts index c75ae32..fa8c0a4 100644 --- a/template/wechatMp/src/init.ts +++ b/template/wechatMp/src/init.ts @@ -1,27 +1,9 @@ -import './utils/polyfill'; -import { BasicFeatures, InitializeWechatMp, } from 'oak-frontend-base'; +import "./utils/polyfill"; +import { InitializeWechatMp, } from 'oak-frontend-base'; import { EntityDict } from 'oak-app-domain'; import { storageSchema, ActionDefDict } from 'oak-app-domain'; -import { aspectDict } from '../../src/aspects'; -import { initialize } from '../../src/features'; -import { checkers } from '../../src/checkers'; -import { triggers } from '../../src/triggers'; -import { data } from '../../src/data'; -import { routers } from '../../src/exceptionRouters'; - - -import { initializeFeatures as initializeGeneralFeatures } from 'oak-general-business'; import { RuntimeContext } from '../../src/RuntimeContext'; - -const { token } = initializeGeneralFeatures(); - -export const createFeatures = (basicFeatures: BasicFeatures) => { - const features = initialize(basicFeatures); - const wholeFeatures = Object.assign({ - token, - }, features); - return wholeFeatures; -} +import { aspectDict, createFeatures, routers, triggers, checkers, data, token } from '../../src/initialize'; const { OakComponent, OakPage, features } = InitializeWechatMp>( storageSchema, @@ -34,6 +16,9 @@ const { OakComponent, OakPage, features } = InitializeWechatMp 65536) { - throw new Error('Can only request a maximum of 65536 bytes') - } - - const { randomValues } = await wx.getRandomValues({ - length, - }); - return new Uint8Array(randomValues); -} - -/** - * 封装wx环境下的fetch,注意有部分属性并非完全吻合,请谨慎使用 - * @param url - * @param options - * @returns - */ +// import '../../../src/utils/polyfill'; Object.assign(global, { + /** + * 封装wx环境下的fetch,注意有部分属性并非完全吻合,请谨慎使用 + * @param url + * @param options + * @returns + */ fetch: async (url: string, options?: Parameters[1]) => { const params = Object.assign({ method: 'GET', @@ -73,5 +61,15 @@ Object.assign(global, { } ); }, - getRandomValues, + getRandomValues: async function getRandomValues(length: number) { + if (length > 65536) { + throw new Error('Can only request a maximum of 65536 bytes') + } + + const { randomValues } = await wx.getRandomValues({ + length, + }); + return new Uint8Array(randomValues); + } + , }); \ No newline at end of file