模板wechatMp的初始化登录以及注入stm
This commit is contained in:
parent
4ab80560db
commit
7d7ba2a1e8
|
|
@ -1,13 +1,36 @@
|
||||||
import './init';
|
import { pick } from 'lodash';
|
||||||
|
import { WechatMpEnv } from 'oak-app-domain/Token/Schema';
|
||||||
|
import { features } from './init';
|
||||||
export interface IAppOption {
|
export interface IAppOption {
|
||||||
globalData: {};
|
globalData: {
|
||||||
|
features: typeof features;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
App<IAppOption>({
|
App<IAppOption>({
|
||||||
globalData: {
|
globalData: {
|
||||||
|
features,
|
||||||
},
|
},
|
||||||
async onLaunch() {
|
async onLaunch() {
|
||||||
console.log('onLaunch');
|
const { code } = await wx.login();
|
||||||
|
const env = await wx.getSystemInfo();
|
||||||
|
const env2 = pick(env, [
|
||||||
|
'brand',
|
||||||
|
'model',
|
||||||
|
'pixelRatio',
|
||||||
|
'screenWidth',
|
||||||
|
'screenHeight',
|
||||||
|
'windowWidth',
|
||||||
|
'windowHeight',
|
||||||
|
'statusBarHeight',
|
||||||
|
'language',
|
||||||
|
'version',
|
||||||
|
'system',
|
||||||
|
'platform',
|
||||||
|
'fontSizeSetting',
|
||||||
|
'SDKVersion'
|
||||||
|
]);
|
||||||
|
await features.token.loginWechatMp(code, Object.assign(env2, { type: 'wechatMp' }) as WechatMpEnv);
|
||||||
},
|
},
|
||||||
|
|
||||||
onHide() {
|
onHide() {
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,44 @@
|
||||||
import { InitializeWechatMp, } from 'oak-frontend-base';
|
import './utils/polyfill';
|
||||||
|
import { BasicFeatures, InitializeWechatMp, } from 'oak-frontend-base';
|
||||||
import { EntityDict } from 'oak-app-domain';
|
import { EntityDict } from 'oak-app-domain';
|
||||||
import { storageSchema } from 'oak-app-domain/Storage';
|
import { storageSchema, ActionDefDict } from 'oak-app-domain';
|
||||||
import { aspectDict } from '../../src/aspects';
|
import { aspectDict } from '../../src/aspects';
|
||||||
import { initialize } from '../../src/features';
|
import { initialize } from '../../src/features';
|
||||||
import { checkers } from '../../src/checkers';
|
import { checkers } from '../../src/checkers';
|
||||||
import { triggers } from '../../src/triggers';
|
import { triggers } from '../../src/triggers';
|
||||||
import { data } from '../../src/data';
|
import { data } from '../../src/data';
|
||||||
|
import { routers } from '../../src/exceptionRouters';
|
||||||
|
|
||||||
|
|
||||||
import { initializeFeatures as initializeGeneralFeatures } from 'oak-general-business';
|
import { initializeFeatures as initializeGeneralFeatures } from 'oak-general-business';
|
||||||
import { RuntimeContext } from '../../src/RuntimeContext';
|
import { RuntimeContext } from '../../src/RuntimeContext';
|
||||||
|
|
||||||
const { token } = initializeGeneralFeatures();
|
const { token } = initializeGeneralFeatures<EntityDict, RuntimeContext, typeof aspectDict>();
|
||||||
|
|
||||||
const { OakComponent, OakPage } = InitializeWechatMp<EntityDict, RuntimeContext, typeof aspectDict, {}>(
|
export const createFeatures = (basicFeatures: BasicFeatures<EntityDict, RuntimeContext, typeof aspectDict>) => {
|
||||||
|
const features = initialize(basicFeatures);
|
||||||
|
const wholeFeatures = Object.assign({
|
||||||
|
token,
|
||||||
|
}, features);
|
||||||
|
return wholeFeatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { OakComponent, OakPage, features } = InitializeWechatMp<EntityDict, RuntimeContext, typeof aspectDict, ReturnType<typeof createFeatures>>(
|
||||||
storageSchema,
|
storageSchema,
|
||||||
(basicFeatures) => {
|
createFeatures,
|
||||||
const features = initialize(basicFeatures);
|
|
||||||
return Object.assign({
|
|
||||||
token,
|
|
||||||
}, features);
|
|
||||||
},
|
|
||||||
(store) => new RuntimeContext(store, data.application[0].id, token.getToken()),
|
(store) => new RuntimeContext(store, data.application[0].id, token.getToken()),
|
||||||
|
routers,
|
||||||
triggers,
|
triggers,
|
||||||
checkers,
|
checkers,
|
||||||
aspectDict,
|
aspectDict,
|
||||||
data as any);
|
data as any,
|
||||||
|
ActionDefDict);
|
||||||
|
|
||||||
Object.assign(global, {
|
Object.assign(global, {
|
||||||
OakPage,
|
OakPage,
|
||||||
OakComponent,
|
OakComponent,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export {
|
||||||
|
features,
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue