提交 7b474871 编写于 作者: Q qiang

chore: Merge branch 'feat-support-xhs' into dev

# Conflicts:
#	packages/uni-cli-shared/lib/platform.js
......@@ -2,7 +2,7 @@
`uni-app` 是一个使用 `Vue.js` 开发小程序、H5、App的统一前端框架。官网地址:[https://uniapp.dcloud.io](https://uniapp.dcloud.io)
开发者使用 `Vue` 语法编写代码,`uni-app` 框架将其编译到 小程序(微信/支付宝/百度/字节跳动/QQ/快手/钉钉)、App(iOS/Android)、H5等多个平台,保证其正确运行并达到优秀体验。
开发者使用 `Vue` 语法编写代码,`uni-app` 框架将其编译到 小程序(微信/支付宝/百度/字节跳动/QQ/快手/钉钉/小红书)、App(iOS/Android)、H5等多个平台,保证其正确运行并达到优秀体验。
# uni-app的特点
......
const path = require('path')
const json = require('@rollup/plugin-json')
const alias = require('@rollup/plugin-alias')
const replace = require('@rollup/plugin-replace')
const PLATFORMS = {
'mp-weixin': {
prefix: 'wx',
title: '微信小程序'
},
'mp-qq': {
prefix: 'wx',
title: 'QQ小程序'
},
'mp-alipay': {
prefix: 'my',
title: '支付宝小程序'
},
'mp-baidu': {
prefix: 'swan',
title: '百度小程序'
},
'mp-toutiao': {
prefix: 'tt',
title: '头条小程序'
},
'mp-kuaishou': {
prefix: 'ks',
title: '快手小程序'
},
'mp-lark': {
prefix: 'tt',
title: '飞书小程序'
},
'mp-jd': {
prefix: 'jd',
title: '京东小程序'
},
'quickapp-webview': {
prefix: 'qa',
title: '快应用(Webview)版'
},
'app-plus': {
prefix: 'wx',
title: 'app-plus'
}
}
const platform = PLATFORMS[process.env.UNI_PLATFORM]
let input = 'src/core/runtime/index.js'
const output = {
file: `packages/uni-${process.env.UNI_PLATFORM}/dist/index.js`,
format: 'es'
}
if (process.env.UNI_MP) {
input = 'src/core/runtime/mp/index.js'
output.file = `packages/uni-${process.env.UNI_PLATFORM}/dist/mp.js`
}
module.exports = {
input,
output,
plugins: [
alias({
entries: [{
find: '@dcloudio',
replacement: path.resolve(__dirname, '../packages')
}, {
find: 'uni-shared/query',
replacement: path.resolve(__dirname, '../src/shared/query.js')
}, {
find: 'uni-shared',
replacement: path.resolve(__dirname, '../src/shared/util.js')
}, {
find: 'uni-platform',
replacement: path.resolve(__dirname, '../src/platforms/' + process.env.UNI_PLATFORM)
}, {
find: 'uni-wrapper',
replacement: path.resolve(__dirname, '../src/core/runtime/wrapper')
}, {
find: 'uni-helpers',
replacement: path.resolve(__dirname, '../src/core/helpers')
}]
}),
json(),
replace({
__GLOBAL__: platform.prefix,
__PLATFORM_TITLE__: platform.title,
__PLATFORM_PREFIX__: JSON.stringify(platform.prefix),
__PLATFORM__: JSON.stringify(process.env.UNI_PLATFORM)
})
],
external: ['vue', '@dcloudio/uni-i18n']
}
const path = require('path')
const json = require('@rollup/plugin-json')
const alias = require('@rollup/plugin-alias')
const replace = require('@rollup/plugin-replace')
const PLATFORMS = {
'mp-weixin': {
prefix: 'wx',
title: '微信小程序'
},
'mp-qq': {
prefix: 'wx',
title: 'QQ小程序'
},
'mp-alipay': {
prefix: 'my',
title: '支付宝小程序'
},
'mp-baidu': {
prefix: 'swan',
title: '百度小程序'
},
'mp-toutiao': {
prefix: 'tt',
title: '头条小程序'
},
'mp-kuaishou': {
prefix: 'ks',
title: '快手小程序'
},
'mp-lark': {
prefix: 'tt',
title: '飞书小程序'
},
'mp-jd': {
prefix: 'jd',
title: '京东小程序'
},
'mp-xhs': {
prefix: 'xhs',
title: '小红书小程序'
},
'quickapp-webview': {
prefix: 'qa',
title: '快应用(Webview)版'
},
'app-plus': {
prefix: 'wx',
title: 'app-plus'
}
}
const platform = PLATFORMS[process.env.UNI_PLATFORM]
let input = 'src/core/runtime/index.js'
const output = {
file: `packages/uni-${process.env.UNI_PLATFORM}/dist/index.js`,
format: 'es'
}
if (process.env.UNI_MP) {
input = 'src/core/runtime/mp/index.js'
output.file = `packages/uni-${process.env.UNI_PLATFORM}/dist/mp.js`
}
module.exports = {
input,
output,
plugins: [
alias({
entries: [{
find: '@dcloudio',
replacement: path.resolve(__dirname, '../packages')
}, {
find: 'uni-shared/query',
replacement: path.resolve(__dirname, '../src/shared/query.js')
}, {
find: 'uni-shared',
replacement: path.resolve(__dirname, '../src/shared/util.js')
}, {
find: 'uni-platform',
replacement: path.resolve(__dirname, '../src/platforms/' + process.env.UNI_PLATFORM)
}, {
find: 'uni-wrapper',
replacement: path.resolve(__dirname, '../src/core/runtime/wrapper')
}, {
find: 'uni-helpers',
replacement: path.resolve(__dirname, '../src/core/helpers')
}]
}),
json(),
replace({
__GLOBAL__: platform.prefix,
__PLATFORM_TITLE__: platform.title,
__PLATFORM_PREFIX__: JSON.stringify(platform.prefix),
__PLATFORM__: JSON.stringify(process.env.UNI_PLATFORM)
})
],
external: ['vue', '@dcloudio/uni-i18n']
}
{
"name": "uni-app",
"version": "0.0.1",
"scripts": {
"lint": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore build src",
"lint:cli": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore packages/uni-cli-shared packages/uni-template-compiler \"packages/uni-*/lib/*.js\" \"packages/vue-cli-*/**/*.js\" \"packages/webpack-uni-*/**/*.js\"",
"dev:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.js",
"build:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js",
"dev:plugin": "cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.plugin.js",
"build:plugin": "cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.plugin.js",
"build:app-plus": "cross-env UNI_PLATFORM=app-plus rollup -c build/rollup.config.mp.js",
"build:app:v3": "npm run lint && npm run build:app:service && npm run build:app:view",
"build:app:service": "cross-env UNI_PLATFORM=app-plus rollup -c build/rollup.config.app.js",
"build:app:view": "cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=app-plus UNI_VIEW=true node build/build.js",
"dev:app:view": "cross-env NODE_ENV=development UNI_WATCH=true UNI_PLATFORM=app-plus UNI_VIEW=true node build/build.js",
"build:mp-qq": "cross-env UNI_PLATFORM=mp-qq rollup -c build/rollup.config.mp.js",
"build:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin rollup -c build/rollup.config.mp.js",
"build:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu rollup -c build/rollup.config.mp.js",
"build:mp-alipay": "cross-env UNI_PLATFORM=mp-alipay rollup -c build/rollup.config.mp.js",
"build:mp-toutiao": "cross-env UNI_PLATFORM=mp-toutiao rollup -c build/rollup.config.mp.js",
"build:mp-kuaishou": "cross-env UNI_PLATFORM=mp-kuaishou rollup -c build/rollup.config.mp.js",
"build:mp-lark": "cross-env UNI_PLATFORM=mp-lark rollup -c build/rollup.config.mp.js",
"build:mp-jd": "cross-env UNI_PLATFORM=mp-jd rollup -c build/rollup.config.mp.js",
"build:quickapp-webview": "cross-env UNI_PLATFORM=quickapp-webview rollup -c build/rollup.config.mp.js",
"build:mp-weixin:mp": "cross-env UNI_PLATFORM=mp-weixin UNI_MP=true rollup -c build/rollup.config.mp.js",
"build:mp-weixin:wxs": "rollup -c build/rollup.config.wxs.js",
"build:quickapp-native": "cross-env NODE_ENV=development node build/build.qa.js && cross-env NODE_ENV=production node build/build.qa.js",
"build:runtime": "npm run lint && npm run build:mp-weixin && npm run build:mp-qq && npm run build:mp-alipay && npm run build:mp-baidu && npm run build:mp-toutiao && npm run build:mp-jd && npm run build:app-plus && npm run build:quickapp-webview && npm run build:quickapp-native && npm run build:mp-kuaishou && npm run build:mp-lark && npm run build:mp-jd",
{
"name": "uni-app",
"version": "0.0.1",
"scripts": {
"lint": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore build src",
"lint:cli": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore packages/uni-cli-shared packages/uni-template-compiler \"packages/uni-*/lib/*.js\" \"packages/vue-cli-*/**/*.js\" \"packages/webpack-uni-*/**/*.js\"",
"dev:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.js",
"build:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js",
"dev:plugin": "cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.plugin.js",
"build:plugin": "cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.plugin.js",
"build:app-plus": "cross-env UNI_PLATFORM=app-plus rollup -c build/rollup.config.mp.js",
"build:app:v3": "npm run lint && npm run build:app:service && npm run build:app:view",
"build:app:service": "cross-env UNI_PLATFORM=app-plus rollup -c build/rollup.config.app.js",
"build:app:view": "cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=app-plus UNI_VIEW=true node build/build.js",
"dev:app:view": "cross-env NODE_ENV=development UNI_WATCH=true UNI_PLATFORM=app-plus UNI_VIEW=true node build/build.js",
"build:mp-qq": "cross-env UNI_PLATFORM=mp-qq rollup -c build/rollup.config.mp.js",
"build:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin rollup -c build/rollup.config.mp.js",
"build:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu rollup -c build/rollup.config.mp.js",
"build:mp-alipay": "cross-env UNI_PLATFORM=mp-alipay rollup -c build/rollup.config.mp.js",
"build:mp-toutiao": "cross-env UNI_PLATFORM=mp-toutiao rollup -c build/rollup.config.mp.js",
"build:mp-kuaishou": "cross-env UNI_PLATFORM=mp-kuaishou rollup -c build/rollup.config.mp.js",
"build:mp-lark": "cross-env UNI_PLATFORM=mp-lark rollup -c build/rollup.config.mp.js",
"build:mp-jd": "cross-env UNI_PLATFORM=mp-jd rollup -c build/rollup.config.mp.js",
"build:mp-xhs": "cross-env UNI_PLATFORM=mp-xhs rollup -c build/rollup.config.mp.js",
"build:quickapp-webview": "cross-env UNI_PLATFORM=quickapp-webview rollup -c build/rollup.config.mp.js",
"build:mp-weixin:mp": "cross-env UNI_PLATFORM=mp-weixin UNI_MP=true rollup -c build/rollup.config.mp.js",
"build:mp-weixin:wxs": "rollup -c build/rollup.config.wxs.js",
"build:quickapp-native": "cross-env NODE_ENV=development node build/build.qa.js && cross-env NODE_ENV=production node build/build.qa.js",
"build:runtime": "npm run lint && npm run build:mp-weixin && npm run build:mp-qq && npm run build:mp-alipay && npm run build:mp-baidu && npm run build:mp-toutiao && npm run build:mp-jd && npm run build:mp-xhs && npm run build:app-plus && npm run build:quickapp-webview && npm run build:quickapp-native && npm run build:mp-kuaishou && npm run build:mp-lark && npm run build:mp-jd",
"build:stat": "npm run lint && rollup -c build/rollup.config.stat.js",
"build:web-view": "rollup -c build/rollup.config.web-view.js",
"test:cli": "cross-env NODE_ENV=test jest",
"test:unit": "cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js",
"release": "npm run lint:cli && lerna publish --force-publish=*",
"release:alpha": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=alpha",
"release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next",
"release:v3": "npm run lint:cli && lerna publish --no-git-tag-version --force-publish=* --npm-tag=v3"
},
"dependencies": {
"base64-arraybuffer": "^0.2.0",
"intersection-observer": "^0.7.0",
"pako": "^1.0.11",
"safe-area-insets": "^1.4.1"
},
"private": true,
"devDependencies": {
"@rollup/plugin-alias": "^3.1.0",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-replace": "^2.3.1",
"@types/html5plus": "^1.0.0",
"@vue/cli-plugin-babel": "^4.3.1",
"@vue/cli-plugin-eslint": "^4.3.1",
"@vue/cli-plugin-unit-mocha": "^4.3.1",
"@vue/cli-service": "^4.3.1",
"@vue/test-utils": "^1.0.0-beta.33",
"babel-eslint": "^10.1.0",
"babylon": "^6.18.0",
"browserslist": "^4.11.1",
"caniuse-lite": "^1.0.30001040",
"chai": "^4.2.0",
"copy": "^0.3.2",
"cross-env": "^7.0.2",
"del": "^5.1.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-loader": "^3.0.3",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-vue": "^6.2.2",
"i18n": "^0.13.3",
"jest": "^25.1.0",
"jsdom": "^16.2.1",
"jsdom-global": "^3.0.2",
"jsonfile": "^6.0.1",
"mustache": "^4.1.0",
"os-locale-s-fix": "^1.0.8-fix-1",
"recast": "^0.20.4",
"rollup": "^2.6.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-terser": "^5.3.0",
"shell-exec": "^1.0.2",
"stricter-htmlparser2": "^3.9.6",
"strip-json-comments": "^3.1.0",
"vue": "^2.6.11",
"vue-router": "^3.0.1",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.42.0",
"webpack-bundle-analyzer": "^3.6.1"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/recommended",
"standard"
],
"globals": {
"App": true,
"Page": true,
"Component": true,
"Behavior": true,
"getApp": true,
"getCurrentPages": true,
"plus": true,
"uni": true,
"Vue": true,
"wx": true,
"my": true,
"swan": true,
"tt": true,
"qh": true,
"qa": true,
"HWH5": true,
"weex": true,
"__id__": true,
"__uniConfig": true,
"__uniRoutes": true,
"__registerPage": true,
"UniViewJSBridge": true,
"UniServiceJSBridge": true,
"__DEV__": true,
"__VIEW__": true,
"__PLATFORM__": true,
"__VERSION__": true,
"__GLOBAL__": true,
"__PLATFORM_TITLE__": true,
"__PLATFORM_PREFIX__": true,
"it": true,
"describe": true,
"expect": true
},
"rules": {
"no-tabs": 0,
"standard/no-callback-literal": 0
},
"parserOptions": {
"parser": "babel-eslint"
}
},
"browserslist": [
"last 3 versions",
"Android >= 4.1",
"ios >= 8"
],
"license": "Apache-2.0",
"main": "index.js",
"description": "",
"author": ""
}
"build:web-view": "rollup -c build/rollup.config.web-view.js",
"test:cli": "cross-env NODE_ENV=test jest",
"test:unit": "cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js",
"release": "npm run lint:cli && lerna publish --force-publish=*",
"release:alpha": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=alpha",
"release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next",
"release:v3": "npm run lint:cli && lerna publish --no-git-tag-version --force-publish=* --npm-tag=v3"
},
"dependencies": {
"base64-arraybuffer": "^0.2.0",
"intersection-observer": "^0.7.0",
"pako": "^1.0.11",
"safe-area-insets": "^1.4.1"
},
"private": true,
"devDependencies": {
"@rollup/plugin-alias": "^3.1.0",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-replace": "^2.3.1",
"@types/html5plus": "^1.0.0",
"@vue/cli-plugin-babel": "^4.3.1",
"@vue/cli-plugin-eslint": "^4.3.1",
"@vue/cli-plugin-unit-mocha": "^4.3.1",
"@vue/cli-service": "^4.3.1",
"@vue/test-utils": "^1.0.0-beta.33",
"babel-eslint": "^10.1.0",
"babylon": "^6.18.0",
"browserslist": "^4.11.1",
"caniuse-lite": "^1.0.30001040",
"chai": "^4.2.0",
"copy": "^0.3.2",
"cross-env": "^7.0.2",
"del": "^5.1.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-loader": "^3.0.3",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-vue": "^6.2.2",
"i18n": "^0.13.3",
"jest": "^25.1.0",
"jsdom": "^16.2.1",
"jsdom-global": "^3.0.2",
"jsonfile": "^6.0.1",
"mustache": "^4.1.0",
"os-locale-s-fix": "^1.0.8-fix-1",
"recast": "^0.20.4",
"rollup": "^2.6.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-terser": "^5.3.0",
"shell-exec": "^1.0.2",
"stricter-htmlparser2": "^3.9.6",
"strip-json-comments": "^3.1.0",
"vue": "^2.6.11",
"vue-router": "^3.0.1",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.42.0",
"webpack-bundle-analyzer": "^3.6.1"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/recommended",
"standard"
],
"globals": {
"App": true,
"Page": true,
"Component": true,
"Behavior": true,
"getApp": true,
"getCurrentPages": true,
"plus": true,
"uni": true,
"Vue": true,
"wx": true,
"my": true,
"swan": true,
"tt": true,
"qh": true,
"qa": true,
"xhs": true,
"HWH5": true,
"weex": true,
"__id__": true,
"__uniConfig": true,
"__uniRoutes": true,
"__registerPage": true,
"UniViewJSBridge": true,
"UniServiceJSBridge": true,
"__DEV__": true,
"__VIEW__": true,
"__PLATFORM__": true,
"__VERSION__": true,
"__GLOBAL__": true,
"__PLATFORM_TITLE__": true,
"__PLATFORM_PREFIX__": true,
"it": true,
"describe": true,
"expect": true
},
"rules": {
"no-tabs": 0,
"standard/no-callback-literal": 0
},
"parserOptions": {
"parser": "babel-eslint"
}
},
"browserslist": [
"last 3 versions",
"Android >= 4.1",
"ios >= 8"
],
"license": "Apache-2.0",
"main": "index.js",
"description": "",
"author": ""
}
\ No newline at end of file
......@@ -148,7 +148,7 @@ module.exports = {
getShadowCss,
getShadowTemplate (colorType = 'grey') {
let tagName = 'cover-image'
if (process.env.UNI_PLATFORM === 'mp-toutiao' || process.env.UNI_PLATFORM === 'mp-lark') {
if (process.env.UNI_PLATFORM === 'mp-toutiao' || process.env.UNI_PLATFORM === 'mp-lark' || process.env.UNI_PLATFORM === 'mp-xhs') {
tagName = 'image'
}
return `<${tagName} src="${getShadowCdn()}/img/shadow-${colorType}.png" style="z-index:998;position:fixed;left:0;top:0;width:100%;height:3px;"/>`
......
const path = require('path')
const initPreprocessContext = require('./preprocess')
const uniI18n = require('@dcloudio/uni-cli-i18n')
const Plugin = {
options: {},
// 初步校验相关配置是否正确
validate: [], // (platformOptions, manifestJson) {},
configureEnv: [], // (){},
// 以 H5 为基准的平台特殊配置
configureH5: [], // (h5Options) {},
configurePages: [], // (pagesJson,manifestJson,loader) {},
// 链式修改 webpack config
chainWebpack: [], // (config, vueOptions, api) {},
// 修改 webpack config
configureWebpack: [], // (config, vueOptions, api) {},
// 配置额外的资源拷贝
copyWebpackOptions: [] // (platformOptions, vueOptions) {}
}
const PLUGIN_KEYS = Object.keys(Plugin)
function initPlugin (plugin) {
let pluginApi
try {
pluginApi = require(path.join(plugin.id, (plugin.config.main || '/lib/uni.config.js')))
} catch (e) {
console.warn(uniI18n.__('cliShared.missingUniConfig', { 0: plugin.id }))
}
pluginApi && PLUGIN_KEYS.forEach(name => {
if (pluginApi[name]) {
if (Array.isArray(Plugin[name])) { // hooks
Plugin[name].push(pluginApi[name])
} else { // options
Object.assign(Plugin[name], pluginApi[name])
}
}
})
}
const pluginRE = /^(uni-|@[\w-]+(\.)?[\w-]+\/uni-)/
function resolvePlugins () {
const pkg = require(path.resolve(process.env.UNI_CLI_CONTEXT, 'package.json'))
return Object.keys(pkg.devDependencies || {})
.concat(Object.keys(pkg.dependencies || {}))
.map(id => {
if (!pluginRE.test(id)) {
return
}
try {
const pluginPkg = require(id + '/package.json')
const config = pluginPkg['uni-app']
if (!config) {
return
}
if (!config.name) {
return console.warn(uniI18n.__('cliShared.missingNameAttribute', { 0: `${id}/package.json->uni-app` }))
}
return {
id,
name: config.name,
config
}
} catch (e) {}
}).filter(Boolean)
}
function initExtends (name, plugin, plugins) {
const extendsPlatform = plugin.config.extends
if (extendsPlatform) {
if (extendsPlatform !== 'h5') {
console.error(uniI18n.__('cliShared.extendOnlySupportH5'))
process.exit(0)
}
if (!plugin) {
console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { 0: extendsPlatform }))
process.exit(0)
}
const extendsPlugin = plugins.find(plugin => plugin.name === extendsPlatform)
process.env.UNI_SUB_PLATFORM = name
process.env.UNI_PLATFORM = extendsPlatform
initPlugin(extendsPlugin)
}
}
module.exports = {
init () {
// compatible with vue-cli-service lint
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
// hack
if (
process.env.UNI_PLATFORM === 'quickapp-webview-huawei' ||
process.env.UNI_PLATFORM === 'quickapp-webview-union'
) {
process.env.UNI_SUB_PLATFORM = process.env.UNI_PLATFORM
process.env.UNI_PLATFORM = 'quickapp-webview'
}
const plugins = resolvePlugins()
const plugin = plugins.find(plugin => plugin.name === process.env.UNI_PLATFORM)
if (!plugin) {
console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { 0: process.env.UNI_PLATFORM }))
process.exit(0)
}
const name = plugin.name
initExtends(name, plugin, plugins)
initPlugin(plugin)
Plugin.name = name
Plugin.id = plugin.id
Plugin.config = plugin.config
Plugin.platforms = plugins.map(plugin => plugin.name)
Plugin.preprocess = initPreprocessContext(name, Plugin.platforms, process.UNI_SCRIPT_DEFINE)
return Plugin
}
}
const path = require('path')
const initPreprocessContext = require('./preprocess')
const uniI18n = require('@dcloudio/uni-cli-i18n')
const Plugin = {
options: {},
// 初步校验相关配置是否正确
validate: [], // (platformOptions, manifestJson) {},
configureEnv: [], // (){},
// 以 H5 为基准的平台特殊配置
configureH5: [], // (h5Options) {},
configurePages: [], // (pagesJson,manifestJson,loader) {},
// 链式修改 webpack config
chainWebpack: [], // (config, vueOptions, api) {},
// 修改 webpack config
configureWebpack: [], // (config, vueOptions, api) {},
// 配置额外的资源拷贝
copyWebpackOptions: [] // (platformOptions, vueOptions) {}
}
const PLUGIN_KEYS = Object.keys(Plugin)
function initPlugin (plugin) {
let pluginApi
try {
pluginApi = require(path.join(plugin.id, (plugin.config.main || '/lib/uni.config.js')))
} catch (e) {
console.warn(uniI18n.__('cliShared.missingUniConfig', { 0: plugin.id }))
}
pluginApi && PLUGIN_KEYS.forEach(name => {
if (pluginApi[name]) {
if (Array.isArray(Plugin[name])) { // hooks
Plugin[name].push(pluginApi[name])
} else { // options
Object.assign(Plugin[name], pluginApi[name])
}
}
})
}
const pluginRE = /^(uni-|@[\w-]+(\.)?[\w-]+\/uni-)/
function resolvePlugins () {
const pkg = require(path.resolve(process.env.UNI_CLI_CONTEXT, 'package.json'))
return Object.keys(pkg.devDependencies || {})
.concat(Object.keys(pkg.dependencies || {}))
.map(id => {
if (!pluginRE.test(id)) {
return
}
try {
const pluginPkg = require(id + '/package.json')
const config = pluginPkg['uni-app']
if (!config) {
return
}
if (!config.name) {
return console.warn(uniI18n.__('cliShared.missingNameAttribute', { 0: `${id}/package.json->uni-app` }))
}
return {
id,
name: config.name,
config
}
} catch (e) {}
}).filter(Boolean)
}
function initExtends (name, plugin, plugins) {
const extendsPlatform = plugin.config.extends
if (extendsPlatform) {
if (extendsPlatform !== 'h5') {
console.error(uniI18n.__('cliShared.extendOnlySupportH5'))
process.exit(0)
}
if (!plugin) {
console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { 0: extendsPlatform }))
process.exit(0)
}
const extendsPlugin = plugins.find(plugin => plugin.name === extendsPlatform)
process.env.UNI_SUB_PLATFORM = name
process.env.UNI_PLATFORM = extendsPlatform
initPlugin(extendsPlugin)
}
}
module.exports = {
init () {
// compatible with vue-cli-service lint
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
// hack
if (
process.env.UNI_PLATFORM === 'quickapp-webview-huawei' ||
process.env.UNI_PLATFORM === 'quickapp-webview-union'
) {
process.env.UNI_SUB_PLATFORM = process.env.UNI_PLATFORM
process.env.UNI_PLATFORM = 'quickapp-webview'
}
const plugins = resolvePlugins()
const plugin = plugins.find(plugin => plugin.name === process.env.UNI_PLATFORM)
if (!plugin) {
console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { 0: process.env.UNI_PLATFORM }))
process.exit(0)
}
const name = plugin.name
initExtends(name, plugin, plugins)
initPlugin(plugin)
Plugin.name = name
Plugin.id = plugin.id
Plugin.config = plugin.config
Plugin.platforms = plugins.map(plugin => plugin.name)
Plugin.preprocess = initPreprocessContext(name, Plugin.platforms, process.UNI_SCRIPT_DEFINE)
return Plugin
}
}
const fileLoader = require('./file-loader.js')
const defaultOptions = {
limit: -1,
fallback: fileLoader
}
const inlineLimit =
process.env.UNI_PLATFORM === 'mp-weixin' ||
process.env.UNI_PLATFORM === 'mp-qq' ||
process.env.UNI_PLATFORM === 'mp-toutiao' ||
process.env.UNI_PLATFORM === 'mp-kuaishou' ||
process.env.UNI_PLATFORM === 'mp-lark' ||
process.env.UNI_PLATFORM === 'mp-jd' ||
process.env.UNI_PLATFORM === 'app-plus' // v2需要base64,v3需要rewriteUrl
// mp-weixin,mp-qq,app-plus 非v3(即:需要base64的平台)
// 将/static/logo.png转换为~@/static/logo.png
// @import,src,background,background-image
const rewriteUrl = inlineLimit ? require('postcss-urlrewrite')({
imports: true,
properties: ['src', 'background', 'background-image'],
rules: [{
from: /^@\//,
to: '~@/'
}, {
from: /^\/([^/])/,
to: '~@/$1'
}]
}) : () => {}
module.exports = {
loader: 'url-loader',
options () {
if (process.env.UNI_PLATFORM === 'h5') {
// h5平台,不对 url-loader 作调整,默认limit:4096,也不修改file-loader输出路径
return {}
}
if (inlineLimit) {
return {
...defaultOptions,
limit: process.env.UNI_USING_V3 ? -1 : 40960 // (主要用于background-image)
}
}
return {
...defaultOptions
}
},
rewriteUrl
}
const fileLoader = require('./file-loader.js')
const defaultOptions = {
limit: -1,
fallback: fileLoader
}
const inlineLimit =
process.env.UNI_PLATFORM === 'mp-weixin' ||
process.env.UNI_PLATFORM === 'mp-qq' ||
process.env.UNI_PLATFORM === 'mp-toutiao' ||
process.env.UNI_PLATFORM === 'mp-kuaishou' ||
process.env.UNI_PLATFORM === 'mp-lark' ||
process.env.UNI_PLATFORM === 'mp-jd' ||
process.env.UNI_PLATFORM === 'mp-xhs' ||
process.env.UNI_PLATFORM === 'app-plus' // v2需要base64,v3需要rewriteUrl
// mp-weixin,mp-qq,app-plus 非v3(即:需要base64的平台)
// 将/static/logo.png转换为~@/static/logo.png
// @import,src,background,background-image
const rewriteUrl = inlineLimit ? require('postcss-urlrewrite')({
imports: true,
properties: ['src', 'background', 'background-image'],
rules: [{
from: /^@\//,
to: '~@/'
}, {
from: /^\/([^/])/,
to: '~@/$1'
}]
}) : () => {}
module.exports = {
loader: 'url-loader',
options () {
if (process.env.UNI_PLATFORM === 'h5') {
// h5平台,不对 url-loader 作调整,默认limit:4096,也不修改file-loader输出路径
return {}
}
if (inlineLimit) {
return {
...defaultOptions,
limit: process.env.UNI_USING_V3 ? -1 : 40960 // (主要用于background-image)
}
}
return {
...defaultOptions
}
},
rewriteUrl
}
# `uni-mp-xhs`
> 处理模板上的差异,比如文件格式模板上的各种指令。
## Usage
```
const uniMpXhs = require('uni-mp-xhs');
// TODO: DEMONSTRATE API
```
此差异已折叠。
const compiler = require('@dcloudio/uni-mp-weixin/lib/uni.compiler.js')
module.exports = Object.assign({}, compiler, {
directive: 'xhs:'
})
module.exports = {
options: {
cssVars: {
'--status-bar-height': '25px',
'--window-top': '0px',
'--window-bottom': '0px',
'--window-left': '0px',
'--window-right': '0px'
},
extnames: {
style: '.css',
template: '.xhsml'
},
project: 'project.config.json',
subPackages: true
},
copyWebpackOptions (platformOptions, vueOptions) {
const copyOptions = ['xhscomponents']
global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/xhscomponents')
})
return copyOptions
}
}
{
"name": "@dcloudio/uni-mp-xhs",
"version": "2.0.0-32920211029001",
"description": "uni-app mp-xhs",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uni-mp-xhs"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "txu",
"license": "Apache-2.0",
"uni-app": {
"name": "mp-xhs",
"title": "小红书小程序"
},
"gitHead": "9e2d0f8e244724fcd64880316c57d837d1778cf8"
}
const PLATFORMS = [
'h5',
'app-plus',
'mp-weixin',
'mp-qq',
'mp-baidu',
'mp-alipay',
'mp-jd',
'mp-toutiao',
'quickapp-native'
]
const DISPLAY = {
'navigationBarBackgroundColor': 'titleBarBackgroundColor',
'navigationBarTextStyle': (style, val) => {
if (val === 'black') {
style.titleBarTextColor = '#000000'
style.statusBarTextStyle = 'dark'
} else {
style.titleBarTextColor = '#ffffff'
style.statusBarTextStyle = 'light'
}
},
'navigationBarTitleText': 'titleBarText',
'navigationStyle': (style, val) => {
if (val === 'custom') {
style.titleBar = false
}
}
}
function parseStyle(style = {}) {
const ret = {}
Object.keys(style).forEach(name => {
if (!PLATFORMS.includes(name)) {
const transform = DISPLAY[name]
if (transform) {
if (typeof transform === 'string') {
ret[transform] = style[name]
} else if (typeof transform === 'function') {
transform(ret, style[name])
}
} else {
ret[name] = style[name]
}
}
})
if (style['quickapp-native']) {
Object.assign(ret, style['quickapp-native'])
}
return ret
}
module.exports = function parseDisplay(manifest, pages, globalStyle = {}) {
const display = {
pages: {}
}
// globalStyle
Object.assign(display, parseStyle(globalStyle))
pages.forEach(page => {
const key = page.path.substr(0, page.path.lastIndexOf('/'))
display.pages[key] = parseStyle(page.style)
})
manifest.display = display
}
const PLATFORMS = [
'h5',
'app-plus',
'mp-weixin',
'mp-qq',
'mp-baidu',
'mp-alipay',
'mp-jd',
'mp-xhs',
'mp-toutiao',
'quickapp-native'
]
const DISPLAY = {
'navigationBarBackgroundColor': 'titleBarBackgroundColor',
'navigationBarTextStyle': (style, val) => {
if (val === 'black') {
style.titleBarTextColor = '#000000'
style.statusBarTextStyle = 'dark'
} else {
style.titleBarTextColor = '#ffffff'
style.statusBarTextStyle = 'light'
}
},
'navigationBarTitleText': 'titleBarText',
'navigationStyle': (style, val) => {
if (val === 'custom') {
style.titleBar = false
}
}
}
function parseStyle(style = {}) {
const ret = {}
Object.keys(style).forEach(name => {
if (!PLATFORMS.includes(name)) {
const transform = DISPLAY[name]
if (transform) {
if (typeof transform === 'string') {
ret[transform] = style[name]
} else if (typeof transform === 'function') {
transform(ret, style[name])
}
} else {
ret[name] = style[name]
}
}
})
if (style['quickapp-native']) {
Object.assign(ret, style['quickapp-native'])
}
return ret
}
module.exports = function parseDisplay(manifest, pages, globalStyle = {}) {
const display = {
pages: {}
}
// globalStyle
Object.assign(display, parseStyle(globalStyle))
pages.forEach(page => {
const key = page.path.substr(0, page.path.lastIndexOf('/'))
display.pages[key] = parseStyle(page.style)
})
manifest.display = display
}
......@@ -15,295 +15,296 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
const OPERATING_TIME = 10; // 数据上报时间 单位s
const DIFF_TIME = 60 * 1000 * 60 * 24;
let pagesData = pagesTitle.pages;
let titleJsons = {};
for (let i in pagesData) {
titleJsons[i] = pagesData[i].navigationBarTitleText || '';
}
const UUID_KEY = '__DC_STAT_UUID';
const UUID_VALUE = '__DC_UUID_VALUE';
function getUuid() {
let uuid = '';
if (get_platform_name() === 'n') {
try {
uuid = plus.runtime.getDCloudId();
} catch (e) {
uuid = '';
}
return uuid
}
try {
uuid = uni.getStorageSync(UUID_KEY);
} catch (e) {
uuid = UUID_VALUE;
}
if (!uuid) {
uuid = Date.now() + '' + Math.floor(Math.random() * 1e7);
try {
uni.setStorageSync(UUID_KEY, uuid);
} catch (e) {
uni.setStorageSync(UUID_KEY, UUID_VALUE);
}
}
return uuid
}
const get_uuid = (statData) => {
// 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个
return sys.deviceId || getUuid()
};
const get_sgin = (statData) => {
let arr = Object.keys(statData);
let sortArr = arr.sort();
let sgin = {};
let sginStr = '';
for (var i in sortArr) {
sgin[sortArr[i]] = statData[sortArr[i]];
sginStr += sortArr[i] + '=' + statData[sortArr[i]] + '&';
}
return {
sign: '',
options: sginStr.substr(0, sginStr.length - 1),
}
};
const get_encodeURIComponent_options = (statData) => {
let data = {};
for (let prop in statData) {
data[prop] = encodeURIComponent(statData[prop]);
}
return data
};
/**
* 获取当前平台
* 移动端 : 'n',
* h5 : 'h5',
* 微信 : 'wx',
* 阿里 : 'ali',
* 百度 : 'bd',
* 头条 : 'tt',
* qq : 'qq',
* 快应用 : 'qn',
* 快手 : 'ks',
* 飞书 : 'lark',
* 快应用 : 'qw',
* 钉钉 : 'dt'
*/
const get_platform_name = () => {
// 苹果审核代码中禁止出现 alipay 字样 ,需要特殊处理一下
const aliArr = ['y', 'a', 'p', 'mp-ali'];
const platformList = {
'app': 'n',
'app-plus': 'n',
h5: 'h5',
'mp-weixin': 'wx',
[aliArr.reverse().join('')]: 'ali',
'mp-baidu': 'bd',
'mp-toutiao': 'tt',
'mp-qq': 'qq',
'quickapp-native': 'qn',
'mp-kuaishou': 'ks',
'mp-lark': 'lark',
'quickapp-webview': 'qw'
};
if (platformList[process.env.VUE_APP_PLATFORM] === 'ali') {
if (my && my.env) {
const clientName = my.env.clientName;
if (clientName === 'ap') return 'ali'
if (clientName === 'dingtalk') return 'dt'
// TODO 缺少 ali 下的其他平台
}
}
return platformList[process.env.VUE_APP_PLATFORM]
};
/**
* 获取小程序 appid
*/
const get_pack_name = () => {
let packName = '';
if (get_platform_name() === 'wx' || get_platform_name() === 'qq') {
// 兼容微信小程序低版本基础库
if (uni.canIUse('getAccountInfoSync')) {
packName = uni.getAccountInfoSync().miniProgram.appId || '';
}
}
if (get_platform_name() === 'n') ;
return packName
};
/**
* 应用版本
*/
const get_version = () => {
return get_platform_name() === 'n' ? plus.runtime.version : ''
};
/**
* 获取渠道
*/
const get_channel = () => {
const platformName = get_platform_name();
let channel = '';
if (platformName === 'n') {
channel = plus.runtime.channel;
}
return channel
};
/**
* 获取小程序场景值
* @param {Object} options 页面信息
*/
const get_scene = (options) => {
const platformName = get_platform_name();
let scene = '';
if (options) {
return options
}
if (platformName === 'wx') {
scene = uni.getLaunchOptionsSync().scene;
}
return scene
};
/**
* 获取拼接参数
*/
const get_splicing = (data) => {
let str = '';
for (var i in data) {
str += i + '=' + data[i] + '&';
}
return str.substr(0, str.length - 1)
};
/**
* 获取页面url,不包含参数
*/
const get_route = (pageVm) => {
let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
let scope_route = _self.$scope && _self.$scope.is;
return mp_route || scope_route || ''
} else {
return _self.route || (_self.$scope && _self.$scope.route) || (_self.$mp && _self.$mp.page.route)
}
};
/**
* 获取页面url, 包含参数
*/
const get_page_route = (pageVm) => {
// 从 app 进入应用 ,没有 $page ,获取不到路由 ,需要获取页面 尝试从 getCurrentPages 获取也页面实例
// FIXME 尽量不使用 getCurrentPages ,大部分获取路由是从 onHide 获取 ,这时可以获取到,如果是 onload ,则可能获取不到,比如 百度
let page = pageVm.$page || (pageVm.$scope && pageVm.$scope.$page);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
if (!page) return lastPageRoute || ''
return page.fullPath === '/' ? page.route : page.fullPath
};
/**
* 获取页面实例
*/
const get_page_vm = () => {
let pages = getCurrentPages();
let $page = pages[pages.length - 1];
if (!$page) return null
return $page.$vm
};
/**
* 获取页面类型
*/
const get_page_types = (self) => {
// XXX 百度有问题 ,获取的都是 componet ,等待修复
if (self.mpType === 'page' || self.$mpType === 'page' || (self.$mp && self.$mp.mpType === 'page') || self
.$options.mpType === 'page') {
return 'page';
}
if (self.mpType === 'app' || self.$mpType === 'app' || (self.$mp && self.$mp.mpType === 'app') || self.$options
.mpType === 'app') {
return 'app'
}
return null;
};
/**
* 处理上报参数
* @param {Object} 需要处理的数据
*/
const handle_data = (statData) => {
let firstArr = [];
let contentArr = [];
let lastArr = [];
for (let i in statData) {
const rd = statData[i];
rd.forEach((elm) => {
const newData = get_splicing(elm);
if (i === 0) {
firstArr.push(newData);
} else if (i === 3) {
lastArr.push(newData);
} else {
contentArr.push(newData);
}
});
}
firstArr.push(...contentArr, ...lastArr);
// 参数需要处理成字符串,方便上传
return JSON.stringify(firstArr)
};
/**
* 自定义事件参数校验
*/
const calibration = (eventName, options) => {
// login 、 share 、pay_success 、pay_fail 、register 、title
if (!eventName) {
console.error(`uni.report Missing [eventName] parameter`);
return true
}
if (typeof eventName !== 'string') {
console.error(`uni.report [eventName] Parameter type error, it can only be of type String`);
return true
}
if (eventName.length > 255) {
console.error(`uni.report [eventName] Parameter length cannot be greater than 255`);
return true
}
if (typeof options !== 'string' && typeof options !== 'object') {
console.error('uni.report [options] Parameter type error, Only supports String or Object type');
return true
}
if (typeof options === 'string' && options.length > 255) {
console.error(`uni.report [options] Parameter length cannot be greater than 255`);
return true
}
if (eventName === 'title' && typeof options !== 'string') {
console.error(
`uni.report [eventName] When the parameter is title, the [options] parameter can only be of type String`
);
return true
}
};
const get_page_name = (routepath) => {
return (titleJsons && titleJsons[routepath]) || ''
let pagesData = pagesTitle.pages;
let titleJsons = {};
for (let i in pagesData) {
titleJsons[i] = pagesData[i].navigationBarTitleText || '';
}
const UUID_KEY = '__DC_STAT_UUID';
const UUID_VALUE = '__DC_UUID_VALUE';
function getUuid() {
let uuid = '';
if (get_platform_name() === 'n') {
try {
uuid = plus.runtime.getDCloudId();
} catch (e) {
uuid = '';
}
return uuid
}
try {
uuid = uni.getStorageSync(UUID_KEY);
} catch (e) {
uuid = UUID_VALUE;
}
if (!uuid) {
uuid = Date.now() + '' + Math.floor(Math.random() * 1e7);
try {
uni.setStorageSync(UUID_KEY, uuid);
} catch (e) {
uni.setStorageSync(UUID_KEY, UUID_VALUE);
}
}
return uuid
}
const get_uuid = (statData) => {
// 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个
return sys.deviceId || getUuid()
};
const get_sgin = (statData) => {
let arr = Object.keys(statData);
let sortArr = arr.sort();
let sgin = {};
let sginStr = '';
for (var i in sortArr) {
sgin[sortArr[i]] = statData[sortArr[i]];
sginStr += sortArr[i] + '=' + statData[sortArr[i]] + '&';
}
return {
sign: '',
options: sginStr.substr(0, sginStr.length - 1),
}
};
const get_encodeURIComponent_options = (statData) => {
let data = {};
for (let prop in statData) {
data[prop] = encodeURIComponent(statData[prop]);
}
return data
};
/**
* 获取当前平台
* 移动端 : 'n',
* h5 : 'h5',
* 微信 : 'wx',
* 阿里 : 'ali',
* 百度 : 'bd',
* 头条 : 'tt',
* qq : 'qq',
* 快应用 : 'qn',
* 快手 : 'ks',
* 飞书 : 'lark',
* 快应用 : 'qw',
* 钉钉 : 'dt'
*/
const get_platform_name = () => {
// 苹果审核代码中禁止出现 alipay 字样 ,需要特殊处理一下
const aliArr = ['y', 'a', 'p', 'mp-ali'];
const platformList = {
'app': 'n',
'app-plus': 'n',
h5: 'h5',
'mp-weixin': 'wx',
[aliArr.reverse().join('')]: 'ali',
'mp-baidu': 'bd',
'mp-toutiao': 'tt',
'mp-qq': 'qq',
'quickapp-native': 'qn',
'mp-kuaishou': 'ks',
'mp-xhs': 'xhs',
'mp-lark': 'lark',
'quickapp-webview': 'qw'
};
if (platformList[process.env.VUE_APP_PLATFORM] === 'ali') {
if (my && my.env) {
const clientName = my.env.clientName;
if (clientName === 'ap') return 'ali'
if (clientName === 'dingtalk') return 'dt'
// TODO 缺少 ali 下的其他平台
}
}
return platformList[process.env.VUE_APP_PLATFORM]
};
/**
* 获取小程序 appid
*/
const get_pack_name = () => {
let packName = '';
if (get_platform_name() === 'wx' || get_platform_name() === 'qq') {
// 兼容微信小程序低版本基础库
if (uni.canIUse('getAccountInfoSync')) {
packName = uni.getAccountInfoSync().miniProgram.appId || '';
}
}
if (get_platform_name() === 'n') ;
return packName
};
/**
* 应用版本
*/
const get_version = () => {
return get_platform_name() === 'n' ? plus.runtime.version : ''
};
/**
* 获取渠道
*/
const get_channel = () => {
const platformName = get_platform_name();
let channel = '';
if (platformName === 'n') {
channel = plus.runtime.channel;
}
return channel
};
/**
* 获取小程序场景值
* @param {Object} options 页面信息
*/
const get_scene = (options) => {
const platformName = get_platform_name();
let scene = '';
if (options) {
return options
}
if (platformName === 'wx') {
scene = uni.getLaunchOptionsSync().scene;
}
return scene
};
/**
* 获取拼接参数
*/
const get_splicing = (data) => {
let str = '';
for (var i in data) {
str += i + '=' + data[i] + '&';
}
return str.substr(0, str.length - 1)
};
/**
* 获取页面url,不包含参数
*/
const get_route = (pageVm) => {
let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
let scope_route = _self.$scope && _self.$scope.is;
return mp_route || scope_route || ''
} else {
return _self.route || (_self.$scope && _self.$scope.route) || (_self.$mp && _self.$mp.page.route)
}
};
/**
* 获取页面url, 包含参数
*/
const get_page_route = (pageVm) => {
// 从 app 进入应用 ,没有 $page ,获取不到路由 ,需要获取页面 尝试从 getCurrentPages 获取也页面实例
// FIXME 尽量不使用 getCurrentPages ,大部分获取路由是从 onHide 获取 ,这时可以获取到,如果是 onload ,则可能获取不到,比如 百度
let page = pageVm.$page || (pageVm.$scope && pageVm.$scope.$page);
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
if (!page) return lastPageRoute || ''
return page.fullPath === '/' ? page.route : page.fullPath
};
/**
* 获取页面实例
*/
const get_page_vm = () => {
let pages = getCurrentPages();
let $page = pages[pages.length - 1];
if (!$page) return null
return $page.$vm
};
/**
* 获取页面类型
*/
const get_page_types = (self) => {
// XXX 百度有问题 ,获取的都是 componet ,等待修复
if (self.mpType === 'page' || self.$mpType === 'page' || (self.$mp && self.$mp.mpType === 'page') || self
.$options.mpType === 'page') {
return 'page';
}
if (self.mpType === 'app' || self.$mpType === 'app' || (self.$mp && self.$mp.mpType === 'app') || self.$options
.mpType === 'app') {
return 'app'
}
return null;
};
/**
* 处理上报参数
* @param {Object} 需要处理的数据
*/
const handle_data = (statData) => {
let firstArr = [];
let contentArr = [];
let lastArr = [];
for (let i in statData) {
const rd = statData[i];
rd.forEach((elm) => {
const newData = get_splicing(elm);
if (i === 0) {
firstArr.push(newData);
} else if (i === 3) {
lastArr.push(newData);
} else {
contentArr.push(newData);
}
});
}
firstArr.push(...contentArr, ...lastArr);
// 参数需要处理成字符串,方便上传
return JSON.stringify(firstArr)
};
/**
* 自定义事件参数校验
*/
const calibration = (eventName, options) => {
// login 、 share 、pay_success 、pay_fail 、register 、title
if (!eventName) {
console.error(`uni.report Missing [eventName] parameter`);
return true
}
if (typeof eventName !== 'string') {
console.error(`uni.report [eventName] Parameter type error, it can only be of type String`);
return true
}
if (eventName.length > 255) {
console.error(`uni.report [eventName] Parameter length cannot be greater than 255`);
return true
}
if (typeof options !== 'string' && typeof options !== 'object') {
console.error('uni.report [options] Parameter type error, Only supports String or Object type');
return true
}
if (typeof options === 'string' && options.length > 255) {
console.error(`uni.report [options] Parameter length cannot be greater than 255`);
return true
}
if (eventName === 'title' && typeof options !== 'string') {
console.error(
`uni.report [eventName] When the parameter is title, the [options] parameter can only be of type String`
);
return true
}
};
const get_page_name = (routepath) => {
return (titleJsons && titleJsons[routepath]) || ''
};
......
import pagesTitle from 'uni-pages?{"type":"style"}'
let pagesData = pagesTitle.pages
let titleJsons = {}
for (let i in pagesData) {
titleJsons[i] = pagesData[i].navigationBarTitleText || ''
}
import {
sys
} from './util.js'
import {
STAT_URL,
STAT_VERSION,
DIFF_TIME
} from '../config.js';
const UUID_KEY = '__DC_STAT_UUID'
const UUID_VALUE = '__DC_UUID_VALUE'
function getUuid() {
let uuid = ''
if (get_platform_name() === 'n') {
try {
uuid = plus.runtime.getDCloudId()
} catch (e) {
uuid = ''
}
return uuid
}
try {
uuid = uni.getStorageSync(UUID_KEY)
} catch (e) {
uuid = UUID_VALUE
}
if (!uuid) {
uuid = Date.now() + '' + Math.floor(Math.random() * 1e7)
try {
uni.setStorageSync(UUID_KEY, uuid)
} catch (e) {
uni.setStorageSync(UUID_KEY, UUID_VALUE)
}
}
return uuid
}
export const get_uuid = (statData) => {
// 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个
return sys.deviceId || getUuid()
}
export const get_sgin = (statData) => {
let arr = Object.keys(statData)
let sortArr = arr.sort()
let sgin = {}
let sginStr = ''
for (var i in sortArr) {
sgin[sortArr[i]] = statData[sortArr[i]]
sginStr += sortArr[i] + '=' + statData[sortArr[i]] + '&'
}
return {
sign: '',
options: sginStr.substr(0, sginStr.length - 1),
}
}
export const get_encodeURIComponent_options = (statData) => {
let data = {}
for (let prop in statData) {
data[prop] = encodeURIComponent(statData[prop])
}
return data
}
/**
* 获取当前平台
* 移动端 : 'n',
* h5 : 'h5',
* 微信 : 'wx',
* 阿里 : 'ali',
* 百度 : 'bd',
* 头条 : 'tt',
* qq : 'qq',
* 快应用 : 'qn',
* 快手 : 'ks',
* 飞书 : 'lark',
* 快应用 : 'qw',
* 钉钉 : 'dt'
*/
export const get_platform_name = () => {
// 苹果审核代码中禁止出现 alipay 字样 ,需要特殊处理一下
const aliArr = ['y', 'a', 'p', 'mp-ali']
const platformList = {
'app': 'n',
'app-plus': 'n',
h5: 'h5',
'mp-weixin': 'wx',
[aliArr.reverse().join('')]: 'ali',
'mp-baidu': 'bd',
'mp-toutiao': 'tt',
'mp-qq': 'qq',
'quickapp-native': 'qn',
'mp-kuaishou': 'ks',
'mp-lark': 'lark',
'quickapp-webview': 'qw'
}
if (platformList[process.env.VUE_APP_PLATFORM] === 'ali') {
if (my && my.env) {
const clientName = my.env.clientName
if (clientName === 'ap') return 'ali'
if (clientName === 'dingtalk') return 'dt'
// TODO 缺少 ali 下的其他平台
}
}
return platformList[process.env.VUE_APP_PLATFORM]
}
/**
* 获取小程序 appid
*/
export const get_pack_name = () => {
let packName = ''
if (get_platform_name() === 'wx' || get_platform_name() === 'qq') {
// 兼容微信小程序低版本基础库
if (uni.canIUse('getAccountInfoSync')) {
packName = uni.getAccountInfoSync().miniProgram.appId || ''
}
}
if (get_platform_name() === 'n') {
// TODO APP 获取包名
}
return packName
}
/**
* 应用版本
*/
export const get_version = () => {
return get_platform_name() === 'n' ? plus.runtime.version : ''
}
/**
* 获取渠道
*/
export const get_channel = () => {
const platformName = get_platform_name()
let channel = ''
if (platformName === 'n') {
channel = plus.runtime.channel
}
if (platformName === 'wx') {
// TODO 需要调研小程序二维码渠道如何获取;
}
return channel
}
/**
* 获取小程序场景值
* @param {Object} options 页面信息
*/
export const get_scene = (options) => {
const platformName = get_platform_name()
let scene = ''
if (options) {
return options
}
if (platformName === 'wx') {
scene = uni.getLaunchOptionsSync().scene
}
return scene
}
/**
* 获取拼接参数
*/
export const get_splicing = (data) => {
let str = ''
for (var i in data) {
str += i + '=' + data[i] + '&'
}
return str.substr(0, str.length - 1)
}
/**
* 获取页面url,不包含参数
*/
export const get_route = (pageVm) => {
let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
let scope_route = _self.$scope && _self.$scope.is;
return mp_route || scope_route || ''
} else {
return _self.route || (_self.$scope && _self.$scope.route) || (_self.$mp && _self.$mp.page.route)
}
};
/**
* 获取页面url, 包含参数
*/
export const get_page_route = (pageVm) => {
// 从 app 进入应用 ,没有 $page ,获取不到路由 ,需要获取页面 尝试从 getCurrentPages 获取也页面实例
// FIXME 尽量不使用 getCurrentPages ,大部分获取路由是从 onHide 获取 ,这时可以获取到,如果是 onload ,则可能获取不到,比如 百度
let page = pageVm.$page || (pageVm.$scope && pageVm.$scope.$page)
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
if (!page) return lastPageRoute || ''
return page.fullPath === '/' ? page.route : page.fullPath
};
/**
* 获取页面实例
*/
export const get_page_vm = () => {
let pages = getCurrentPages()
let $page = pages[pages.length - 1]
if (!$page) return null
return $page.$vm
}
/**
* 获取页面类型
*/
export const get_page_types = (self) => {
// XXX 百度有问题 ,获取的都是 componet ,等待修复
if (self.mpType === 'page' || self.$mpType === 'page' || (self.$mp && self.$mp.mpType === 'page') || self
.$options.mpType === 'page') {
return 'page';
}
if (self.mpType === 'app' || self.$mpType === 'app' || (self.$mp && self.$mp.mpType === 'app') || self.$options
.mpType === 'app') {
return 'app'
}
return null;
}
/**
* 处理上报参数
* @param {Object} 需要处理的数据
*/
export const handle_data = (statData) => {
let firstArr = []
let contentArr = []
let lastArr = []
for (let i in statData) {
const rd = statData[i]
rd.forEach((elm) => {
const newData = get_splicing(elm)
if (i === 0) {
firstArr.push(newData)
} else if (i === 3) {
lastArr.push(newData)
} else {
contentArr.push(newData)
}
})
}
firstArr.push(...contentArr, ...lastArr)
// 参数需要处理成字符串,方便上传
return JSON.stringify(firstArr)
}
/**
* 自定义事件参数校验
*/
export const calibration = (eventName, options) => {
// login 、 share 、pay_success 、pay_fail 、register 、title
if (!eventName) {
console.error(`uni.report Missing [eventName] parameter`);
return true
}
if (typeof eventName !== 'string') {
console.error(`uni.report [eventName] Parameter type error, it can only be of type String`);
return true
}
if (eventName.length > 255) {
console.error(`uni.report [eventName] Parameter length cannot be greater than 255`);
return true
}
if (typeof options !== 'string' && typeof options !== 'object') {
console.error('uni.report [options] Parameter type error, Only supports String or Object type');
return true
}
if (typeof options === 'string' && options.length > 255) {
console.error(`uni.report [options] Parameter length cannot be greater than 255`);
return true
}
if (eventName === 'title' && typeof options !== 'string') {
console.error(
`uni.report [eventName] When the parameter is title, the [options] parameter can only be of type String`
);
return true
}
}
export const get_page_name = (routepath) => {
return (titleJsons && titleJsons[routepath]) || ''
import pagesTitle from 'uni-pages?{"type":"style"}'
let pagesData = pagesTitle.pages
let titleJsons = {}
for (let i in pagesData) {
titleJsons[i] = pagesData[i].navigationBarTitleText || ''
}
import {
sys
} from './util.js'
import {
STAT_URL,
STAT_VERSION,
DIFF_TIME
} from '../config.js';
const UUID_KEY = '__DC_STAT_UUID'
const UUID_VALUE = '__DC_UUID_VALUE'
function getUuid() {
let uuid = ''
if (get_platform_name() === 'n') {
try {
uuid = plus.runtime.getDCloudId()
} catch (e) {
uuid = ''
}
return uuid
}
try {
uuid = uni.getStorageSync(UUID_KEY)
} catch (e) {
uuid = UUID_VALUE
}
if (!uuid) {
uuid = Date.now() + '' + Math.floor(Math.random() * 1e7)
try {
uni.setStorageSync(UUID_KEY, uuid)
} catch (e) {
uni.setStorageSync(UUID_KEY, UUID_VALUE)
}
}
return uuid
}
export const get_uuid = (statData) => {
// 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个
return sys.deviceId || getUuid()
}
export const get_sgin = (statData) => {
let arr = Object.keys(statData)
let sortArr = arr.sort()
let sgin = {}
let sginStr = ''
for (var i in sortArr) {
sgin[sortArr[i]] = statData[sortArr[i]]
sginStr += sortArr[i] + '=' + statData[sortArr[i]] + '&'
}
return {
sign: '',
options: sginStr.substr(0, sginStr.length - 1),
}
}
export const get_encodeURIComponent_options = (statData) => {
let data = {}
for (let prop in statData) {
data[prop] = encodeURIComponent(statData[prop])
}
return data
}
/**
* 获取当前平台
* 移动端 : 'n',
* h5 : 'h5',
* 微信 : 'wx',
* 阿里 : 'ali',
* 百度 : 'bd',
* 头条 : 'tt',
* qq : 'qq',
* 快应用 : 'qn',
* 快手 : 'ks',
* 飞书 : 'lark',
* 快应用 : 'qw',
* 钉钉 : 'dt'
*/
export const get_platform_name = () => {
// 苹果审核代码中禁止出现 alipay 字样 ,需要特殊处理一下
const aliArr = ['y', 'a', 'p', 'mp-ali']
const platformList = {
'app': 'n',
'app-plus': 'n',
h5: 'h5',
'mp-weixin': 'wx',
[aliArr.reverse().join('')]: 'ali',
'mp-baidu': 'bd',
'mp-toutiao': 'tt',
'mp-qq': 'qq',
'quickapp-native': 'qn',
'mp-kuaishou': 'ks',
'mp-xhs': 'xhs',
'mp-lark': 'lark',
'quickapp-webview': 'qw'
}
if (platformList[process.env.VUE_APP_PLATFORM] === 'ali') {
if (my && my.env) {
const clientName = my.env.clientName
if (clientName === 'ap') return 'ali'
if (clientName === 'dingtalk') return 'dt'
// TODO 缺少 ali 下的其他平台
}
}
return platformList[process.env.VUE_APP_PLATFORM]
}
/**
* 获取小程序 appid
*/
export const get_pack_name = () => {
let packName = ''
if (get_platform_name() === 'wx' || get_platform_name() === 'qq') {
// 兼容微信小程序低版本基础库
if (uni.canIUse('getAccountInfoSync')) {
packName = uni.getAccountInfoSync().miniProgram.appId || ''
}
}
if (get_platform_name() === 'n') {
// TODO APP 获取包名
}
return packName
}
/**
* 应用版本
*/
export const get_version = () => {
return get_platform_name() === 'n' ? plus.runtime.version : ''
}
/**
* 获取渠道
*/
export const get_channel = () => {
const platformName = get_platform_name()
let channel = ''
if (platformName === 'n') {
channel = plus.runtime.channel
}
if (platformName === 'wx') {
// TODO 需要调研小程序二维码渠道如何获取;
}
return channel
}
/**
* 获取小程序场景值
* @param {Object} options 页面信息
*/
export const get_scene = (options) => {
const platformName = get_platform_name()
let scene = ''
if (options) {
return options
}
if (platformName === 'wx') {
scene = uni.getLaunchOptionsSync().scene
}
return scene
}
/**
* 获取拼接参数
*/
export const get_splicing = (data) => {
let str = ''
for (var i in data) {
str += i + '=' + data[i] + '&'
}
return str.substr(0, str.length - 1)
}
/**
* 获取页面url,不包含参数
*/
export const get_route = (pageVm) => {
let _self = pageVm || get_page_vm();
if (get_platform_name() === 'bd') {
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
let scope_route = _self.$scope && _self.$scope.is;
return mp_route || scope_route || ''
} else {
return _self.route || (_self.$scope && _self.$scope.route) || (_self.$mp && _self.$mp.page.route)
}
};
/**
* 获取页面url, 包含参数
*/
export const get_page_route = (pageVm) => {
// 从 app 进入应用 ,没有 $page ,获取不到路由 ,需要获取页面 尝试从 getCurrentPages 获取也页面实例
// FIXME 尽量不使用 getCurrentPages ,大部分获取路由是从 onHide 获取 ,这时可以获取到,如果是 onload ,则可能获取不到,比如 百度
let page = pageVm.$page || (pageVm.$scope && pageVm.$scope.$page)
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
if (!page) return lastPageRoute || ''
return page.fullPath === '/' ? page.route : page.fullPath
};
/**
* 获取页面实例
*/
export const get_page_vm = () => {
let pages = getCurrentPages()
let $page = pages[pages.length - 1]
if (!$page) return null
return $page.$vm
}
/**
* 获取页面类型
*/
export const get_page_types = (self) => {
// XXX 百度有问题 ,获取的都是 componet ,等待修复
if (self.mpType === 'page' || self.$mpType === 'page' || (self.$mp && self.$mp.mpType === 'page') || self
.$options.mpType === 'page') {
return 'page';
}
if (self.mpType === 'app' || self.$mpType === 'app' || (self.$mp && self.$mp.mpType === 'app') || self.$options
.mpType === 'app') {
return 'app'
}
return null;
}
/**
* 处理上报参数
* @param {Object} 需要处理的数据
*/
export const handle_data = (statData) => {
let firstArr = []
let contentArr = []
let lastArr = []
for (let i in statData) {
const rd = statData[i]
rd.forEach((elm) => {
const newData = get_splicing(elm)
if (i === 0) {
firstArr.push(newData)
} else if (i === 3) {
lastArr.push(newData)
} else {
contentArr.push(newData)
}
})
}
firstArr.push(...contentArr, ...lastArr)
// 参数需要处理成字符串,方便上传
return JSON.stringify(firstArr)
}
/**
* 自定义事件参数校验
*/
export const calibration = (eventName, options) => {
// login 、 share 、pay_success 、pay_fail 、register 、title
if (!eventName) {
console.error(`uni.report Missing [eventName] parameter`);
return true
}
if (typeof eventName !== 'string') {
console.error(`uni.report [eventName] Parameter type error, it can only be of type String`);
return true
}
if (eventName.length > 255) {
console.error(`uni.report [eventName] Parameter length cannot be greater than 255`);
return true
}
if (typeof options !== 'string' && typeof options !== 'object') {
console.error('uni.report [options] Parameter type error, Only supports String or Object type');
return true
}
if (typeof options === 'string' && options.length > 255) {
console.error(`uni.report [options] Parameter length cannot be greater than 255`);
return true
}
if (eventName === 'title' && typeof options !== 'string') {
console.error(
`uni.report [eventName] When the parameter is title, the [options] parameter can only be of type String`
);
return true
}
}
export const get_page_name = (routepath) => {
return (titleJsons && titleJsons[routepath]) || ''
}
......
const fs = require('fs')
const path = require('path')
const moduleAlias = require('module-alias')
const {
hasModule
} = require('@dcloudio/uni-cli-shared/lib/util')
const isInHBuilderX = fs.existsSync(path.resolve(process.env.UNI_CLI_CONTEXT, 'bin/uniapp-cli.js'))
// nvue override
moduleAlias.addAlias('weex-styler', path.resolve(__dirname, 'packages/weex-styler'))
moduleAlias.addAlias('weex-template-compiler', path.resolve(__dirname, 'packages/weex-template-compiler'))
moduleAlias.addAlias('@vue/component-compiler-utils', require.resolve(
'@dcloudio/vue-cli-plugin-uni/packages/@vue/component-compiler-utils'))
moduleAlias.addAlias('@vue/component-compiler-utils/package.json', require.resolve(
'@dcloudio/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/package.json'))
if (isInHBuilderX) {
moduleAlias.addAlias('typescript', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-typescript/node_modules/typescript'))
moduleAlias.addAlias('less', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-less/node_modules/less'))
moduleAlias.addAlias('node-sass', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-node-sass/node_modules/node-sass-china'))
moduleAlias.addAlias('stylus', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-stylus/node_modules/stylus'))
moduleAlias.addAlias('pug', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-pug-cli/node_modules/pug'))
if (!hasModule('typescript')) { // 因为 cli-plugin-typescript 会直接读取typescript/package.json,故,如果未安装 typescript,则先设置一个假的
moduleAlias.addAlias('typescript/package.json', path.resolve(__dirname, 'typescript.json'))
moduleAlias.addAlias('fork-ts-checker-webpack-plugin', path.resolve(__dirname,
'fork-ts-checker-webpack-plugin.fake.js'))
}
const path = require('path')
const moduleAlias = require('module-alias')
const {
hasModule
} = require('@dcloudio/uni-cli-shared/lib/util')
const isInHBuilderX = fs.existsSync(path.resolve(process.env.UNI_CLI_CONTEXT, 'bin/uniapp-cli.js'))
// nvue override
moduleAlias.addAlias('weex-styler', path.resolve(__dirname, 'packages/weex-styler'))
moduleAlias.addAlias('weex-template-compiler', path.resolve(__dirname, 'packages/weex-template-compiler'))
moduleAlias.addAlias('@vue/component-compiler-utils', require.resolve(
'@dcloudio/vue-cli-plugin-uni/packages/@vue/component-compiler-utils'))
moduleAlias.addAlias('@vue/component-compiler-utils/package.json', require.resolve(
'@dcloudio/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/package.json'))
if (isInHBuilderX) {
moduleAlias.addAlias('typescript', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-typescript/node_modules/typescript'))
moduleAlias.addAlias('less', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-less/node_modules/less'))
moduleAlias.addAlias('node-sass', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-node-sass/node_modules/node-sass-china'))
moduleAlias.addAlias('stylus', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-stylus/node_modules/stylus'))
moduleAlias.addAlias('pug', path.resolve(process.env.UNI_HBUILDERX_PLUGINS,
'compile-pug-cli/node_modules/pug'))
if (!hasModule('typescript')) { // 因为 cli-plugin-typescript 会直接读取typescript/package.json,故,如果未安装 typescript,则先设置一个假的
moduleAlias.addAlias('typescript/package.json', path.resolve(__dirname, 'typescript.json'))
moduleAlias.addAlias('fork-ts-checker-webpack-plugin', path.resolve(__dirname,
'fork-ts-checker-webpack-plugin.fake.js'))
}
}
......@@ -294,8 +294,8 @@ const modes = ['legacy', 'auto', 'augmented']
const scopedSlotsCompiler = !platformOptions.scopedSlotsCompiler && platformOptions.betterScopedSlots ? modes[2]
: platformOptions.scopedSlotsCompiler
process.env.SCOPED_SLOTS_COMPILER = modes.includes(scopedSlotsCompiler) ? scopedSlotsCompiler : modes[1]
// 快手小程序抽象组件编译报错,如未指定 legacy 固定为 augmented 模式
if (process.env.UNI_PLATFORM === 'mp-kuaishou' && process.env.SCOPED_SLOTS_COMPILER !== modes[0]) {
// 快手小程序、小红书小程序 抽象组件编译报错,如未指定 legacy 固定为 augmented 模式
if ((process.env.UNI_PLATFORM === 'mp-kuaishou' || process.env.UNI_PLATFORM === 'mp-xhs') && process.env.SCOPED_SLOTS_COMPILER !== modes[0]) {
process.env.SCOPED_SLOTS_COMPILER = modes[2]
}
......
......@@ -4616,7 +4616,7 @@ function initProps (vm, propsOptions) {
defineReactive$$1(props, key, value, function () {
if (!isRoot && !isUpdatingChildComponent) {
{
if(vm.mpHost === 'mp-baidu' || vm.mpHost === 'mp-kuaishou'){//百度、快手 observer 在 setData callback 之后触发,直接忽略该 warn
if(vm.mpHost === 'mp-baidu' || vm.mpHost === 'mp-kuaishou' || vm.mpHost === 'mp-xhs'){//百度、快手、小红书 observer 在 setData callback 之后触发,直接忽略该 warn
return
}
//fixed by xxxxxx __next_tick_pending,uni://form-field 时不告警
......
......@@ -85,6 +85,7 @@ const getPlatformName = () => {
'mp-toutiao': 'tt',
'mp-qq': 'qq',
'mp-jd': 'jd',
'mp-xhs': 'xhs',
'quickapp-native': 'qn',
'mp-kuaishou': 'ks',
};
......
......@@ -83,6 +83,7 @@ const getPlatformName = () => {
'mp-toutiao': 'tt',
'mp-qq': 'qq',
'mp-jd': 'jd',
'mp-xhs': 'xhs',
'quickapp-native': 'qn',
'mp-kuaishou': 'ks',
};
......
const {
getPlatformExts
} = require('../shared')
const {
getShadowCss,
getPlatformGlobal
} = require('@dcloudio/uni-cli-shared')
const {
getSpecialMethods
} = require('@dcloudio/uni-cli-shared/lib/cache')
module.exports = function generateApp (compilation) {
const ext = getPlatformExts().style
let importMainCss = ''
let importVendorCss = ''
if (
process.env.NODE_ENV === 'production' &&
process.env.UNI_PLATFORM !== 'app-plus'
) {
const targetCssName = `common/main${ext}`
if (!compilation.assets[targetCssName]) {
compilation.assets[targetCssName] = {
size () {
return Buffer.byteLength(getShadowCss(), 'utf8')
},
source () {
return getShadowCss()
}
}
} else {
const source = compilation.assets[targetCssName].source() + getShadowCss()
compilation.assets[targetCssName] = {
size () {
return Buffer.byteLength(source, 'utf8')
},
source () {
return source
}
}
}
}
// 框架预设样式 用于隐藏自定义组件
// TODO 分平台 import 不同 css
const platforms = ['mp-weixin', 'mp-qq', 'mp-jd', 'mp-toutiao', 'mp-lark']
const presetStyle = platforms.includes(process.env.UNI_PLATFORM) ? '[data-custom-hidden="true"],[bind-data-custom-hidden="true"]{display: none !important;}' : ''
if (compilation.assets[`common/main${ext}`]) { // 是否存在 main.css
importMainCss = `@import './common/main${ext}';`
}
if (compilation.assets[`common/vendor${ext}`]) { // 是否存在 vendor.css
importVendorCss += `@import './common/vendor${ext}';`
}
const runtimeJsPath = 'common/runtime.js'
const asset = compilation.assets[runtimeJsPath]
if ( // app 和 baidu 不需要
process.env.UNI_PLATFORM !== 'app-plus' &&
process.env.UNI_PLATFORM !== 'mp-baidu' &&
asset &&
!asset.source.__$wrappered
) {
const source =
`
!function(){try{var a=Function("return this")();a&&!a.Math&&(Object.assign(a,{isFinite:isFinite,Array:Array,Date:Date,Error:Error,Function:Function,Math:Math,Object:Object,RegExp:RegExp,String:String,TypeError:TypeError,setTimeout:setTimeout,clearTimeout:clearTimeout,setInterval:setInterval,clearInterval:clearInterval}),"undefined"!=typeof Reflect&&(a.Reflect=Reflect))}catch(a){}}();
${asset.source()}
`
const newSource = function () {
return source
}
newSource.__$wrappered = true
compilation.assets[runtimeJsPath].source = newSource
}
const specialMethods = getSpecialMethods()
let beforeCode = ''
if (Object.keys(specialMethods).length) {
beforeCode = `${getPlatformGlobal()}.specialMethods = ${JSON.stringify(specialMethods)}`
}
return [{
file: 'app.js',
source: `${beforeCode}
require('./common/runtime.js')
require('./common/vendor.js')
require('./common/main.js')`
}, {
file: 'app' + ext,
source: `${importMainCss}
${importVendorCss}
${presetStyle}`
}]
}
const {
getPlatformExts
} = require('../shared')
const {
getShadowCss,
getPlatformGlobal
} = require('@dcloudio/uni-cli-shared')
const {
getSpecialMethods
} = require('@dcloudio/uni-cli-shared/lib/cache')
module.exports = function generateApp (compilation) {
const ext = getPlatformExts().style
let importMainCss = ''
let importVendorCss = ''
if (
process.env.NODE_ENV === 'production' &&
process.env.UNI_PLATFORM !== 'app-plus'
) {
const targetCssName = `common/main${ext}`
if (!compilation.assets[targetCssName]) {
compilation.assets[targetCssName] = {
size () {
return Buffer.byteLength(getShadowCss(), 'utf8')
},
source () {
return getShadowCss()
}
}
} else {
const source = compilation.assets[targetCssName].source() + getShadowCss()
compilation.assets[targetCssName] = {
size () {
return Buffer.byteLength(source, 'utf8')
},
source () {
return source
}
}
}
}
// 框架预设样式 用于隐藏自定义组件
// TODO 分平台 import 不同 css
const platforms = ['mp-weixin', 'mp-qq', 'mp-jd', 'mp-xhs', 'mp-toutiao', 'mp-lark']
const presetStyle = platforms.includes(process.env.UNI_PLATFORM) ? '[data-custom-hidden="true"],[bind-data-custom-hidden="true"]{display: none !important;}' : ''
if (compilation.assets[`common/main${ext}`]) { // 是否存在 main.css
importMainCss = `@import './common/main${ext}';`
}
if (compilation.assets[`common/vendor${ext}`]) { // 是否存在 vendor.css
importVendorCss += `@import './common/vendor${ext}';`
}
const runtimeJsPath = 'common/runtime.js'
const asset = compilation.assets[runtimeJsPath]
if ( // app 和 baidu 不需要
process.env.UNI_PLATFORM !== 'app-plus' &&
process.env.UNI_PLATFORM !== 'mp-baidu' &&
asset &&
!asset.source.__$wrappered
) {
const source =
`
!function(){try{var a=Function("return this")();a&&!a.Math&&(Object.assign(a,{isFinite:isFinite,Array:Array,Date:Date,Error:Error,Function:Function,Math:Math,Object:Object,RegExp:RegExp,String:String,TypeError:TypeError,setTimeout:setTimeout,clearTimeout:clearTimeout,setInterval:setInterval,clearInterval:clearInterval}),"undefined"!=typeof Reflect&&(a.Reflect=Reflect))}catch(a){}}();
${asset.source()}
`
const newSource = function () {
return source
}
newSource.__$wrappered = true
compilation.assets[runtimeJsPath].source = newSource
}
const specialMethods = getSpecialMethods()
let beforeCode = ''
if (Object.keys(specialMethods).length) {
beforeCode = `${getPlatformGlobal()}.specialMethods = ${JSON.stringify(specialMethods)}`
}
return [{
file: 'app.js',
source: `${beforeCode}
require('./common/runtime.js')
require('./common/vendor.js')
require('./common/main.js')`
}, {
file: 'app' + ext,
source: `${importMainCss}
${importVendorCss}
${presetStyle}`
}]
}
module.exports = function (pagesJson, manifestJson) {
const {
app,
project
} = require('../mp')(pagesJson, manifestJson, require('./project.config.json'))
return [app, project]
}
{
"setting": {
"urlCheck": true,
"es6": false,
"postcss": false,
"minified": false,
"newFeature": true
},
"appid": "testAppId",
"projectname": ""
}
此差异已折叠。
import {
noop
}
from 'uni-shared'
const sharedPropertyDefinition = {
enumerable: true,
configurable: true,
get: noop,
set: noop
}
export function proxy (target, sourceKey, key) {
sharedPropertyDefinition.get = function proxyGetter () {
return this[sourceKey][key]
}
sharedPropertyDefinition.set = function proxySetter (val) {
this[sourceKey][key] = val
}
Object.defineProperty(target, key, sharedPropertyDefinition)
import {
noop
}
from 'uni-shared'
const sharedPropertyDefinition = {
enumerable: true,
configurable: true,
get: noop,
set: noop
}
export function proxy (target, sourceKey, key) {
sharedPropertyDefinition.get = function proxyGetter () {
return this[sourceKey][key]
}
sharedPropertyDefinition.set = function proxySetter (val) {
this[sourceKey][key] = val
}
Object.defineProperty(target, key, sharedPropertyDefinition)
}
import {
hasOwn
} from 'uni-shared'
import {
initWebviewApi as initAppplusWebviewApi
} from 'uni-platforms/app-plus/runtime/web-view'
import {
initWebviewApi as initH5WebviewApi
} from 'uni-platforms/h5/runtime/web-view'
import {
initWebviewApi as initAlipayWebviewApi
} from 'uni-platforms/mp-alipay/runtime/web-view'
import {
initWebviewApi as initBaiduWebviewApi
} from 'uni-platforms/mp-baidu/runtime/web-view'
import {
initWebviewApi as initQQWebviewApi
} from 'uni-platforms/mp-qq/runtime/web-view'
import {
initWebviewApi as initToutiaoWebviewApi
} from 'uni-platforms/mp-toutiao/runtime/web-view'
import {
initWebviewApi as initWeixinWebviewApi
} from 'uni-platforms/mp-weixin/runtime/web-view'
import {
initWebviewApi as initQuickappWebviewApi
} from 'uni-platforms/quickapp-webview/runtime/web-view'
import {
initWebviewApi as initKuaishouWebviewApi
} from 'uni-platforms/mp-kuaishou/runtime/web-view'
import {
initWebviewApi as initLarkWebviewApi
} from 'uni-platforms/mp-lark/runtime/web-view'
import {
initWebviewApi as initJDWebviewApi
} from 'uni-platforms/mp-jd/runtime/web-view'
const UniAppJSBridgeReady = function () {
window.UniAppJSBridge = true
document.dispatchEvent(new CustomEvent('UniAppJSBridgeReady', {
bubbles: true,
cancelable: true
}))
}
const initWebviewApis = [
initAppplusWebviewApi,
initWeixinWebviewApi,
initQQWebviewApi,
initAlipayWebviewApi,
initBaiduWebviewApi,
initToutiaoWebviewApi,
initQuickappWebviewApi,
initKuaishouWebviewApi,
initLarkWebviewApi,
initJDWebviewApi,
initH5WebviewApi
]
let webViewApi
for (let i = 0; i < initWebviewApis.length; i++) {
webViewApi = initWebviewApis[i](UniAppJSBridgeReady)
if (webViewApi) {
break
}
}
if (!webViewApi) {
webViewApi = {}
}
const api = typeof uni !== 'undefined' ? uni : {}
if (!api.navigateTo) {
for (const key in webViewApi) {
if (hasOwn(webViewApi, key)) {
api[key] = webViewApi[key]
}
}
}
api.webView = webViewApi
export default api
import {
hasOwn
} from 'uni-shared'
import {
initWebviewApi as initAppplusWebviewApi
} from 'uni-platforms/app-plus/runtime/web-view'
import {
initWebviewApi as initH5WebviewApi
} from 'uni-platforms/h5/runtime/web-view'
import {
initWebviewApi as initAlipayWebviewApi
} from 'uni-platforms/mp-alipay/runtime/web-view'
import {
initWebviewApi as initBaiduWebviewApi
} from 'uni-platforms/mp-baidu/runtime/web-view'
import {
initWebviewApi as initQQWebviewApi
} from 'uni-platforms/mp-qq/runtime/web-view'
import {
initWebviewApi as initToutiaoWebviewApi
} from 'uni-platforms/mp-toutiao/runtime/web-view'
import {
initWebviewApi as initWeixinWebviewApi
} from 'uni-platforms/mp-weixin/runtime/web-view'
import {
initWebviewApi as initQuickappWebviewApi
} from 'uni-platforms/quickapp-webview/runtime/web-view'
import {
initWebviewApi as initKuaishouWebviewApi
} from 'uni-platforms/mp-kuaishou/runtime/web-view'
import {
initWebviewApi as initLarkWebviewApi
} from 'uni-platforms/mp-lark/runtime/web-view'
import {
initWebviewApi as initJDWebviewApi
} from 'uni-platforms/mp-jd/runtime/web-view'
import {
initWebviewApi as initXhsWebviewApi
} from 'uni-platforms/mp-xhs/runtime/web-view'
const UniAppJSBridgeReady = function () {
window.UniAppJSBridge = true
document.dispatchEvent(new CustomEvent('UniAppJSBridgeReady', {
bubbles: true,
cancelable: true
}))
}
const initWebviewApis = [
initAppplusWebviewApi,
initWeixinWebviewApi,
initQQWebviewApi,
initAlipayWebviewApi,
initBaiduWebviewApi,
initToutiaoWebviewApi,
initQuickappWebviewApi,
initKuaishouWebviewApi,
initLarkWebviewApi,
initJDWebviewApi,
initXhsWebviewApi,
initH5WebviewApi
]
let webViewApi
for (let i = 0; i < initWebviewApis.length; i++) {
webViewApi = initWebviewApis[i](UniAppJSBridgeReady)
if (webViewApi) {
break
}
}
if (!webViewApi) {
webViewApi = {}
}
const api = typeof uni !== 'undefined' ? uni : {}
if (!api.navigateTo) {
for (const key in webViewApi) {
if (hasOwn(webViewApi, key)) {
api[key] = webViewApi[key]
}
}
}
api.webView = webViewApi
export default api
此差异已折叠。
......@@ -106,7 +106,7 @@ export default function parseBaseApp (vm, {
initRefs
}) {
initEventChannel()
if (__PLATFORM__ === 'mp-weixin' || __PLATFORM__ === 'mp-qq' || __PLATFORM__ === 'mp-jd' || __PLATFORM__ === 'mp-toutiao' || __PLATFORM__ ===
if (__PLATFORM__ === 'mp-weixin' || __PLATFORM__ === 'mp-qq' || __PLATFORM__ === 'mp-jd' || __PLATFORM__ === 'mp-xhs' || __PLATFORM__ === 'mp-toutiao' || __PLATFORM__ ===
'mp-kuaishou' || __PLATFORM__ === 'mp-alipay' || __PLATFORM__ === 'mp-baidu' || __PLATFORM__ === 'mp-lark') {
initScopedSlotsParams()
}
......
# `uni-mp-xhs`
> 处理运行时 API 兼容。
此差异已折叠。
此差异已折叠。
import '../../mp-weixin/runtime/index'
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册