diff --git a/config/loaders/wxml-loader.js b/config/loaders/wxml-loader.js index 2c0c9d0..3ab7b07 100644 --- a/config/loaders/wxml-loader.js +++ b/config/loaders/wxml-loader.js @@ -19,6 +19,9 @@ module.exports = function (content) { // const callback = this.async(); // console.log(content, options); + /** + * domparser会自动给没有value的attribute赋上值,目前改不动 + */ const doc = new DOMParser().parseFromString(content, 'text/xml'); traverse(doc, (node) => { if (node.nodeType === node.ELEMENT_NODE) { diff --git a/src/template.ts b/src/template.ts index a2c71c7..af1eff0 100644 --- a/src/template.ts +++ b/src/template.ts @@ -206,6 +206,7 @@ export function projectConfigContentWithWeChatMp( export function appJsonContentWithWeChatMp(isDev: boolean) { const pages = []; if (isDev) { + pages.push("@oak-general-business/token/login/index"); pages.push('@oak-general-business/address/list/index'); pages.push('@oak-general-business/address/upsert/index'); pages.push('@oak-general-business/pickers/area/index'); @@ -219,7 +220,8 @@ export function appJsonContentWithWeChatMp(isDev: boolean) { "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "Weixin", - "navigationBarTextStyle":"black" + "navigationBarTextStyle":"black", + "enablePullDownRefresh": true }, "style": "v2", "sitemapLocation": "sitemap.json" diff --git a/template/wechatMp/src/typings/polyfill.d.ts b/template/wechatMp/src/typings/polyfill.d.ts index 3828572..284fa07 100644 --- a/template/wechatMp/src/typings/polyfill.d.ts +++ b/template/wechatMp/src/typings/polyfill.d.ts @@ -1,9 +1,11 @@ import { MakeOakComponent, MakeOakPage } from 'oak-frontend-base'; import { EntityDict } from 'oak-app-domain/EntityDict'; -import { GeneralRuntimeContext, aspectDict } from 'oak-general-business'; +import { RuntimeContext } from '../../../src/RuntimeContext'; +import { aspectDict } from '../../../src/aspects'; +import { createFeatures } from '../init'; declare global { - const OakPage: MakeOakPage, typeof aspectDict, {}>; - const OakComponent: MakeOakComponent, typeof aspectDict, {}>; + const OakPage: MakeOakPage>; + const OakComponent: MakeOakComponent>; } export {} \ No newline at end of file diff --git a/template/wechatMp/src/utils/polyfill.ts b/template/wechatMp/src/utils/polyfill.ts new file mode 100644 index 0000000..90c28d2 --- /dev/null +++ b/template/wechatMp/src/utils/polyfill.ts @@ -0,0 +1,65 @@ + +/** + * 封装wx环境下的fetch,注意有部分属性并非完全吻合,请谨慎使用 + * @param url + * @param options + * @returns + */ +const fetch2 = async (url: string, options?: Parameters[1]) => { + const params = Object.assign({ + method: 'GET', + dataType: '其他', + responseType: 'text', + headers: { + 'Content-type': 'application/json', + }, + }, options); + const { method, headers, dataType, responseType, body } = params; + + let responseType2 = responseType; + if ((headers as Record)['Accept'] === 'application/octet-stream') { + responseType2 = 'arraybuffer'; + } + + if (!['text', 'arraybuffer'].includes(responseType2)) { + throw new Error(`传入不支持的responseType: ${responseType2}`); + } + + let dataType2 = dataType === 'json' ? dataType : '其他'; + if (responseType2 === 'arraybuffer') { + dataType2 = '其他'; + } + + return new Promise( + (resolve, reject) => { + wx.request({ + url, + data: body || {}, + method: method as any, + header: headers, + dataType: dataType2 as any, + responseType: responseType2 as any, + success: (res) => { + const { statusCode, data, header } = res; + const result = Object.assign({}, res, { + status: statusCode, + ok: statusCode === 200, + headers: header, + arrayBuffer: async () => data as ArrayBuffer, + json: async () => JSON.parse(data as string), + text: async () => data as string, + clone: () => result!, + url, + statusText: statusCode === 200 ? 'ok' : 'error', + }); + return resolve(result); + }, + fail: reject, + }); + } + ); +} + +Object.assign(global, { + fetch: fetch2, +}); \ No newline at end of file