import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid'; export async function createWechatLogin(params, context) { const { type, interval, qrCodeType = "wechatPublic", router } = params; let userId; if (type === 'bind') { userId = context.getCurrentUserId(); } const id = await generateNewIdAsync(); let _router = router; // router为空则默认为/wechatLogin/confirm if (!router) { _router = { pathname: '/wechatLogin/confirm', props: { oakId: id, }, }; } else { _router.props = { oakId: id, }; } const createData = { id, type, expiresAt: Date.now() + interval, expired: false, qrCodeType, successed: false, router: _router, }; if (userId) { createData.userId = userId; } if (type === 'login') { const closeRoot = context.openRootMode(); await context.operate('wechatLogin', { id: await generateNewIdAsync(), action: 'create', data: createData, }, { dontCollect: true, }); closeRoot(); } else { await context.operate('wechatLogin', { id: await generateNewIdAsync(), action: 'create', data: createData, }, { dontCollect: true, }); } return id; }