diff --git a/packages/api-proxy/src/common/js/index.js b/packages/api-proxy/src/common/js/index.js index e74f2dfc36..5bd7df03f2 100644 --- a/packages/api-proxy/src/common/js/index.js +++ b/packages/api-proxy/src/common/js/index.js @@ -1,3 +1,3 @@ export * from './web' export * from './utils' -export * from './toPromise' \ No newline at end of file +export * from './toPromise' diff --git a/packages/api-proxy/src/platform/api/request/tenonUtil.js b/packages/api-proxy/src/platform/api/request/tenonUtil.js index e69de29bb2..54d18ff1fb 100644 --- a/packages/api-proxy/src/platform/api/request/tenonUtil.js +++ b/packages/api-proxy/src/platform/api/request/tenonUtil.js @@ -0,0 +1,80 @@ +function typeEqual (obj, type) { + return Object.prototype.toString.call(obj) === '[object ' + type + ']' +} + +function isStr (obj) { + return typeEqual(obj, 'String') +} + +export function queryParse (search = '') { + const arr = search.split(/(\?|&)/) + const parmsObj = {} + + for (let i = 0; i < arr.length; i++) { + if (arr[i].indexOf('=') !== -1) { + const keyValue = arr[i].match(/([^=]*)=(.*)/) + parmsObj[keyValue[1]] = decodeURIComponent(keyValue[2]) + } + } + + if (JSON.stringify(parmsObj) === '{}') { + // 如果解析失败,返回原值 + return search + } + + return parmsObj +} + +export function tryJsonParse (some) { + // 这里eslint提示也先别删除\[\] + // eslint-disable-next-line no-useless-escape + if (isStr(some) && /[\{\[].*[\}\]]/.test(some)) { + try { + some = JSON.parse(some) + } catch (err) {} + } + + return some +} + +export function parseHeader (headers) { + // fetch中的headers value为数组形式,其他端为字符串形式, 统一为字符串 + // header的key值统一为小写 + const result = {} + Object.keys(headers).forEach(key => { + let value = headers[key] + + if (value instanceof Array) { + value = value[0] + } + + result[key.toLowerCase()] = value + }) + return JSON.stringify(result) +} + +export function queryStringify (obj) { + const strArr = [] + let keys = null + + if (obj && Object.keys(obj).length > 0) { + keys = Object.keys(obj) + + for (let i = 0; i < keys.length; i++) { + const key = keys[i] + strArr.push(`${key}=${encodeURIComponent(obj[key])}`) + } + } + + return strArr.join('&') +} +export function buildQueryStringUrl (params, url = '') { + if (!url) return queryStringify(params) + let retUrl = url + + if (queryStringify(params)) { + retUrl = url.indexOf('?') > -1 ? `${url}&${queryStringify(params)}` : `${url}?${queryStringify(params)}` + } + + return retUrl +} diff --git a/packages/core/src/platform/patch/getDefaultOptions.tenon.js b/packages/core/src/platform/patch/getDefaultOptions.tenon.js index 0eccb2bf53..9338e62afc 100644 --- a/packages/core/src/platform/patch/getDefaultOptions.tenon.js +++ b/packages/core/src/platform/patch/getDefaultOptions.tenon.js @@ -38,7 +38,7 @@ function initProxy (context, rawOptions) { } } -export function getDefaultOptions ({type, rawOptions = {}, currentInject }) { +export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) { const rawSetup = rawOptions.setup if (rawSetup) { rawOptions.setup = (props) => { diff --git a/packages/webpack-plugin/lib/index.js b/packages/webpack-plugin/lib/index.js index 5df3260933..bcd2efbdb7 100644 --- a/packages/webpack-plugin/lib/index.js +++ b/packages/webpack-plugin/lib/index.js @@ -1880,7 +1880,7 @@ try { if (tenonStyleLoaderIndex > -1 && !isPitcherRequest) { loaders.splice(tenonStyleLoaderIndex + 1, 0, { loader: normalize.lib('style-compiler/index.js'), - options: (mpxStyleOptions && JSON.parse(mpxStyleOptions)) || {} + options: (queryObj.mpxStyleOptions && JSON.parse(queryObj.mpxStyleOptions)) || {} }) } } else if (mpxStyleLoaderIndex === -1) { diff --git a/packages/webpack-plugin/lib/loader.js b/packages/webpack-plugin/lib/loader.js index d17241d69e..8975f1010d 100644 --- a/packages/webpack-plugin/lib/loader.js +++ b/packages/webpack-plugin/lib/loader.js @@ -135,7 +135,6 @@ module.exports = function (content) { const hasComment = templateAttrs && templateAttrs.comments const isNative = false - if (mode === 'tenon') { let output = '' if (ctorType === 'app' && !queryObj.app) { diff --git a/packages/webpack-plugin/lib/runtime/optionProcessor.tenon.js b/packages/webpack-plugin/lib/runtime/optionProcessor.tenon.js index 1e50eac06b..80a2c67173 100644 --- a/packages/webpack-plugin/lib/runtime/optionProcessor.tenon.js +++ b/packages/webpack-plugin/lib/runtime/optionProcessor.tenon.js @@ -12,7 +12,7 @@ export function processComponentOption ( componentGenerics, genericsInfo, wxsMixin, - hasApp, + hasApp } ) { if (ctorType === 'app') { @@ -48,9 +48,9 @@ export function processComponentOption ( if (wxsMixin) { if (option.mixins) { - option.mixins.push(mixin) + option.mixins.push(wxsMixin) } else { - option.mixins = [mixin] + option.mixins = [wxsMixin] } } diff --git a/packages/webpack-plugin/lib/tenon/index.js b/packages/webpack-plugin/lib/tenon/index.js index b19eba2b5e..1a4e183d52 100644 --- a/packages/webpack-plugin/lib/tenon/index.js +++ b/packages/webpack-plugin/lib/tenon/index.js @@ -5,12 +5,10 @@ const processTemplate = require('./processTemplate') const processStyles = require('./processStyles') const processScript = require('./processScript') const RecordLoaderContentDependency = require('../dependencies/RecordLoaderContentDependency') -const {stringifyRequest} = require('./script-helper') +const { stringifyRequest } = require('./script-helper') const addQuery = require('../utils/add-query') const parseRequest = require('../utils/parse-request') - - module.exports = function ({ parts, jsonContent, @@ -30,15 +28,12 @@ module.exports = function ({ autoScope, callback }) { - let output = '' - - const mpx = loaderContext.getMpx() // const hasComment = parts.template && parts.template.attrs && parts.template.attrs.comments // const isNative = false const mode = mpx.mode - // const srcMode = mpx.srcMode + srcMode = mpx.srcMode const env = mpx.env const defs = mpx.defs const resolveMode = mpx.resolveMode diff --git a/packages/webpack-plugin/lib/tenon/processScript.js b/packages/webpack-plugin/lib/tenon/processScript.js index abeb08c332..317fe3a9e6 100644 --- a/packages/webpack-plugin/lib/tenon/processScript.js +++ b/packages/webpack-plugin/lib/tenon/processScript.js @@ -7,8 +7,6 @@ const async = require('async') const createJSONHelper = require('../json-compiler/helper') const addQuery = require('../utils/add-query') - - const { buildComponentsMap, getRequireScript, @@ -33,7 +31,6 @@ module.exports = function (script, { }, callback) { const { projectRoot, appInfo, webConfig } = loaderContext.getMpx() - // add entry // const checkEntryDeps = (callback) => { // callback = callback || cacheCallback @@ -146,10 +143,8 @@ module.exports = function (script, { hasApp = false } - // 获取组件集合 const componentsMap = buildComponentsMap({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig }) - // 获取pageConfig const pageConfig = {} if (ctorType === 'page') { diff --git a/packages/webpack-plugin/lib/tenon/processTemplate.js b/packages/webpack-plugin/lib/tenon/processTemplate.js index aba7b34e15..c61da17e3d 100644 --- a/packages/webpack-plugin/lib/tenon/processTemplate.js +++ b/packages/webpack-plugin/lib/tenon/processTemplate.js @@ -4,7 +4,6 @@ const addQuery = require('../utils/add-query') const path = require('path') const parseRequest = require('../utils/parse-request') - module.exports = function (template, { loaderContext, hasScoped, @@ -84,7 +83,7 @@ module.exports = function (template, { // web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空 globalComponents: [], // web模式下实现抽象组件 - componentGenerics, + componentGenerics }) // if (parsed.meta.wxsModuleMap) { // wxsModuleMap = parsed.meta.wxsModuleMap