├── echarts
├── static
│ ├── .gitkeep
│ └── ec-canvas
│ │ ├── ec-canvas.json
│ │ ├── ec-canvas.wxss
│ │ ├── ec-canvas.wxml
│ │ ├── wx-canvas.js
│ │ └── ec-canvas.js
├── .eslintignore
├── config
│ ├── prod.env.js
│ ├── dev.env.js
│ └── index.js
├── docs
│ └── dev.png
├── src
│ ├── pages
│ │ └── bar
│ │ │ ├── main.js
│ │ │ ├── main.json
│ │ │ └── index.vue
│ ├── main.js
│ ├── app.json
│ └── App.vue
├── .postcssrc.js
├── .editorconfig
├── .gitignore
├── index.html
├── build
│ ├── dev-client.js
│ ├── vue-loader.conf.js
│ ├── build.js
│ ├── check-versions.js
│ ├── utils.js
│ ├── webpack.dev.conf.js
│ ├── dev-server.js
│ ├── webpack.base.conf.js
│ └── webpack.prod.conf.js
├── .babelrc
├── project.config.json
├── .eslintrc.js
├── package.json
└── README.md
├── readme.md
└── .gitignore
/echarts/static/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/echarts/.eslintignore:
--------------------------------------------------------------------------------
1 | build/*.js
2 | config/*.js
3 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # examples
2 |
3 | > mpvue 的各种用法示例。
4 |
--------------------------------------------------------------------------------
/echarts/config/prod.env.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | NODE_ENV: '"production"'
3 | }
4 |
--------------------------------------------------------------------------------
/echarts/docs/dev.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpvue/examples/HEAD/echarts/docs/dev.png
--------------------------------------------------------------------------------
/echarts/static/ec-canvas/ec-canvas.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true,
3 | "usingComponents": {}
4 | }
--------------------------------------------------------------------------------
/echarts/static/ec-canvas/ec-canvas.wxss:
--------------------------------------------------------------------------------
1 | .ec-canvas {
2 | width: 100%;
3 | height: 100%;
4 | }
5 |
--------------------------------------------------------------------------------
/echarts/src/pages/bar/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './index'
3 |
4 | const app = new Vue(App)
5 | app.$mount()
6 |
--------------------------------------------------------------------------------
/echarts/src/pages/bar/main.json:
--------------------------------------------------------------------------------
1 | {
2 | "usingComponents": {
3 | "ec-canvas": "../../../static/ec-canvas/ec-canvas"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/echarts/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-mpvue-wxss": {}
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/echarts/config/dev.env.js:
--------------------------------------------------------------------------------
1 | var merge = require('webpack-merge')
2 | var prodEnv = require('./prod.env')
3 |
4 | module.exports = merge(prodEnv, {
5 | NODE_ENV: '"development"'
6 | })
7 |
--------------------------------------------------------------------------------
/echarts/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './App'
3 |
4 | Vue.config.productionTip = false
5 | App.mpType = 'app'
6 |
7 | const app = new Vue(App)
8 | app.$mount()
9 |
--------------------------------------------------------------------------------
/echarts/static/ec-canvas/ec-canvas.wxml:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/echarts/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | *.suo
11 | *.ntvs*
12 | *.njsproj
13 | *.sln
14 |
--------------------------------------------------------------------------------
/echarts/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | *.suo
11 | *.ntvs*
12 | *.njsproj
13 | *.sln
14 |
--------------------------------------------------------------------------------
/echarts/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | my-project
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/echarts/src/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | "pages/bar/main"
4 | ],
5 | "window": {
6 | "backgroundTextStyle": "light",
7 | "navigationBarBackgroundColor": "#fff",
8 | "navigationBarTitleText": "WeChat",
9 | "navigationBarTextStyle": "black"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/echarts/build/dev-client.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | require('eventsource-polyfill')
3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
4 |
5 | hotClient.subscribe(function (event) {
6 | if (event.action === 'reload') {
7 | window.location.reload()
8 | }
9 | })
10 |
--------------------------------------------------------------------------------
/echarts/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", {
4 | "modules": false,
5 | "targets": {
6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7 | }
8 | }],
9 | "stage-2"
10 | ],
11 | "plugins": ["transform-runtime"],
12 | "env": {
13 | "test": {
14 | "presets": ["env", "stage-2"],
15 | "plugins": ["istanbul"]
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/echarts/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils')
2 | var config = require('../config')
3 | // var isProduction = process.env.NODE_ENV === 'production'
4 | // for mp
5 | var isProduction = true
6 |
7 | module.exports = {
8 | loaders: utils.cssLoaders({
9 | sourceMap: isProduction
10 | ? config.build.productionSourceMap
11 | : config.dev.cssSourceMap,
12 | extract: isProduction
13 | }),
14 | transformToRequire: {
15 | video: 'src',
16 | source: 'src',
17 | img: 'src',
18 | image: 'xlink:href'
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/echarts/src/App.vue:
--------------------------------------------------------------------------------
1 |
8 |
9 |
27 |
--------------------------------------------------------------------------------
/echarts/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "项目配置文件。",
3 | "setting": {
4 | "urlCheck": true,
5 | "es6": true,
6 | "postcss": true,
7 | "minified": true,
8 | "newFeature": true
9 | },
10 | "miniprogramRoot": "./dist/",
11 | "compileType": "miniprogram",
12 | "appid": "touristappid",
13 | "projectname": "echarts",
14 | "condition": {
15 | "search": {
16 | "current": -1,
17 | "list": []
18 | },
19 | "conversation": {
20 | "current": -1,
21 | "list": []
22 | },
23 | "game": {
24 | "currentL": -1,
25 | "list": []
26 | },
27 | "miniprogram": {
28 | "current": -1,
29 | "list": []
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/echarts/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // http://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parser: 'babel-eslint',
6 | parserOptions: {
7 | sourceType: 'module'
8 | },
9 | env: {
10 | browser: false,
11 | node: true,
12 | es6: true
13 | },
14 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md
15 | extends: 'standard',
16 | // required to lint *.vue files
17 | plugins: [
18 | 'html'
19 | ],
20 | // add your custom rules here
21 | 'rules': {
22 | // allow paren-less arrow functions
23 | 'arrow-parens': 0,
24 | // allow async-await
25 | 'generator-star-spacing': 0,
26 | // allow debugger during development
27 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
28 | },
29 | globals: {
30 | App: true,
31 | Page: true,
32 | wx: true,
33 | getApp: true,
34 | getPage: true,
35 | requirePlugin: true
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/echarts/build/build.js:
--------------------------------------------------------------------------------
1 | require('./check-versions')()
2 |
3 | process.env.NODE_ENV = 'production'
4 |
5 | var ora = require('ora')
6 | var rm = require('rimraf')
7 | var path = require('path')
8 | var chalk = require('chalk')
9 | var webpack = require('webpack')
10 | var config = require('../config')
11 | var webpackConfig = require('./webpack.prod.conf')
12 |
13 | var spinner = ora('building for production...')
14 | spinner.start()
15 |
16 | rm(path.join(config.build.assetsRoot, '*'), err => {
17 | if (err) throw err
18 | webpack(webpackConfig, function (err, stats) {
19 | spinner.stop()
20 | if (err) throw err
21 | process.stdout.write(stats.toString({
22 | colors: true,
23 | modules: false,
24 | children: false,
25 | chunks: false,
26 | chunkModules: false
27 | }) + '\n\n')
28 |
29 | if (stats.hasErrors()) {
30 | console.log(chalk.red(' Build failed with errors.\n'))
31 | process.exit(1)
32 | }
33 |
34 | console.log(chalk.cyan(' Build complete.\n'))
35 | console.log(chalk.yellow(
36 | ' Tip: built files are meant to be served over an HTTP server.\n' +
37 | ' Opening index.html over file:// won\'t work.\n'
38 | ))
39 | })
40 | })
41 |
--------------------------------------------------------------------------------
/echarts/build/check-versions.js:
--------------------------------------------------------------------------------
1 | var chalk = require('chalk')
2 | var semver = require('semver')
3 | var packageConfig = require('../package.json')
4 | var shell = require('shelljs')
5 | function exec (cmd) {
6 | return require('child_process').execSync(cmd).toString().trim()
7 | }
8 |
9 | var versionRequirements = [
10 | {
11 | name: 'node',
12 | currentVersion: semver.clean(process.version),
13 | versionRequirement: packageConfig.engines.node
14 | }
15 | ]
16 |
17 | if (shell.which('npm')) {
18 | versionRequirements.push({
19 | name: 'npm',
20 | currentVersion: exec('npm --version'),
21 | versionRequirement: packageConfig.engines.npm
22 | })
23 | }
24 |
25 | module.exports = function () {
26 | var warnings = []
27 | for (var i = 0; i < versionRequirements.length; i++) {
28 | var mod = versionRequirements[i]
29 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
30 | warnings.push(mod.name + ': ' +
31 | chalk.red(mod.currentVersion) + ' should be ' +
32 | chalk.green(mod.versionRequirement)
33 | )
34 | }
35 | }
36 |
37 | if (warnings.length) {
38 | console.log('')
39 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
40 | console.log()
41 | for (var i = 0; i < warnings.length; i++) {
42 | var warning = warnings[i]
43 | console.log(' ' + warning)
44 | }
45 | console.log()
46 | process.exit(1)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/echarts/config/index.js:
--------------------------------------------------------------------------------
1 | // see http://vuejs-templates.github.io/webpack for documentation.
2 | var path = require('path')
3 |
4 | module.exports = {
5 | build: {
6 | env: require('./prod.env'),
7 | index: path.resolve(__dirname, '../dist/index.html'),
8 | assetsRoot: path.resolve(__dirname, '../dist'),
9 | assetsSubDirectory: '',
10 | assetsPublicPath: '/',
11 | productionSourceMap: false,
12 | // Gzip off by default as many popular static hosts such as
13 | // Surge or Netlify already gzip all static assets for you.
14 | // Before setting to `true`, make sure to:
15 | // npm install --save-dev compression-webpack-plugin
16 | productionGzip: false,
17 | productionGzipExtensions: ['js', 'css'],
18 | // Run the build command with an extra argument to
19 | // View the bundle analyzer report after build finishes:
20 | // `npm run build --report`
21 | // Set to `true` or `false` to always turn it on or off
22 | bundleAnalyzerReport: process.env.npm_config_report
23 | },
24 | dev: {
25 | env: require('./dev.env'),
26 | port: 8080,
27 | // 在小程序开发者工具中不需要自动打开浏览器
28 | autoOpenBrowser: false,
29 | assetsSubDirectory: '',
30 | assetsPublicPath: '/',
31 | proxyTable: {},
32 | // CSS Sourcemaps off by default because relative paths are "buggy"
33 | // with this option, according to the CSS-Loader README
34 | // (https://github.com/webpack/css-loader#sourcemaps)
35 | // In our experience, they generally work as expected,
36 | // just be aware of this issue when enabling this option.
37 | cssSourceMap: false
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/echarts/static/ec-canvas/wx-canvas.js:
--------------------------------------------------------------------------------
1 | export default class WxCanvas {
2 | constructor(ctx, domId, opts) {
3 | this.ctx = ctx;
4 | this.opts = opts || {};
5 | this.chart = null;
6 |
7 | // this._initCanvas(zrender, ctx);
8 | this._initStyle(ctx);
9 | this._initEvent();
10 | }
11 |
12 | getContext(contextType) {
13 | if (contextType === '2d') {
14 | return this.ctx;
15 | }
16 | }
17 |
18 | setChart(chart) {
19 | this.chart = chart;
20 | }
21 |
22 | attachEvent () {
23 | // noop
24 | }
25 |
26 | detachEvent() {
27 | // noop
28 | }
29 |
30 | _initCanvas(zrender, ctx) {
31 | zrender.util.getContext = function () {
32 | return ctx;
33 | };
34 |
35 | zrender.util.$override('measureText', function (text, font) {
36 | ctx.font = font || '12px sans-serif';
37 | return ctx.measureText(text);
38 | });
39 | }
40 |
41 | _initStyle(ctx) {
42 | var styles = ['fillStyle', 'strokeStyle', 'globalAlpha',
43 | 'textAlign', 'textBaseAlign', 'shadow', 'lineWidth',
44 | 'lineCap', 'lineJoin', 'lineDash', 'miterLimit', 'fontSize'];
45 |
46 | styles.forEach(style => {
47 | Object.defineProperty(ctx, style, {
48 | set: value => {
49 | if (style !== 'fillStyle' && style !== 'strokeStyle'
50 | || value !== 'none' && value !== null
51 | ) {
52 | ctx['set' + style.charAt(0).toUpperCase() + style.slice(1)](value);
53 | }
54 | }
55 | });
56 | });
57 |
58 | ctx.createRadialGradient = () => {
59 | return ctx.createCircularGradient(arguments);
60 | };
61 | }
62 |
63 | _initEvent() {
64 | this.event = {};
65 | const eventNames = [{
66 | wxName: 'touchStart',
67 | ecName: 'mousedown'
68 | }, {
69 | wxName: 'touchMove',
70 | ecName: 'mousemove'
71 | }, {
72 | wxName: 'touchEnd',
73 | ecName: 'mouseup'
74 | }, {
75 | wxName: 'touchEnd',
76 | ecName: 'click'
77 | }];
78 |
79 | eventNames.forEach(name => {
80 | this.event[name.wxName] = e => {
81 | const touch = e.touches[0];
82 | this.chart._zr.handler.dispatch(name.ecName, {
83 | zrX: name.wxName === 'tap' ? touch.clientX : touch.x,
84 | zrY: name.wxName === 'tap' ? touch.clientY : touch.y
85 | });
86 | };
87 | });
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/echarts/build/utils.js:
--------------------------------------------------------------------------------
1 | var path = require('path')
2 | var config = require('../config')
3 | var ExtractTextPlugin = require('extract-text-webpack-plugin')
4 |
5 | exports.assetsPath = function (_path) {
6 | var assetsSubDirectory = process.env.NODE_ENV === 'production'
7 | ? config.build.assetsSubDirectory
8 | : config.dev.assetsSubDirectory
9 | return path.posix.join(assetsSubDirectory, _path)
10 | }
11 |
12 | exports.cssLoaders = function (options) {
13 | options = options || {}
14 |
15 | var cssLoader = {
16 | loader: 'css-loader',
17 | options: {
18 | minimize: process.env.NODE_ENV === 'production',
19 | sourceMap: options.sourceMap
20 | }
21 | }
22 |
23 | var postcssLoader = {
24 | loader: 'postcss-loader',
25 | options: {
26 | sourceMap: true
27 | }
28 | }
29 |
30 | var px2rpxLoader = {
31 | loader: 'px2rpx-loader',
32 | options: {
33 | baseDpr: 1,
34 | rpxUnit: 0.5
35 | }
36 | }
37 |
38 | // generate loader string to be used with extract text plugin
39 | function generateLoaders (loader, loaderOptions) {
40 | var loaders = [cssLoader, px2rpxLoader, postcssLoader]
41 | if (loader) {
42 | loaders.push({
43 | loader: loader + '-loader',
44 | options: Object.assign({}, loaderOptions, {
45 | sourceMap: options.sourceMap
46 | })
47 | })
48 | }
49 |
50 | // Extract CSS when that option is specified
51 | // (which is the case during production build)
52 | if (options.extract) {
53 | return ExtractTextPlugin.extract({
54 | use: loaders,
55 | fallback: 'vue-style-loader'
56 | })
57 | } else {
58 | return ['vue-style-loader'].concat(loaders)
59 | }
60 | }
61 |
62 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html
63 | return {
64 | css: generateLoaders(),
65 | wxss: generateLoaders(),
66 | postcss: generateLoaders(),
67 | less: generateLoaders('less'),
68 | sass: generateLoaders('sass', { indentedSyntax: true }),
69 | scss: generateLoaders('sass'),
70 | stylus: generateLoaders('stylus'),
71 | styl: generateLoaders('stylus')
72 | }
73 | }
74 |
75 | // Generate loaders for standalone style files (outside of .vue)
76 | exports.styleLoaders = function (options) {
77 | var output = []
78 | var loaders = exports.cssLoaders(options)
79 | for (var extension in loaders) {
80 | var loader = loaders[extension]
81 | output.push({
82 | test: new RegExp('\\.' + extension + '$'),
83 | use: loader
84 | })
85 | }
86 | return output
87 | }
88 |
--------------------------------------------------------------------------------
/echarts/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "echarts",
3 | "version": "1.0.0",
4 | "description": "A Mpvue project",
5 | "author": "anchengjian ",
6 | "private": true,
7 | "scripts": {
8 | "dev": "node build/dev-server.js",
9 | "start": "node build/dev-server.js",
10 | "build": "node build/build.js",
11 | "lint": "eslint --ext .js,.vue src"
12 | },
13 | "dependencies": {
14 | "mpvue": "^1.0.11"
15 | },
16 | "devDependencies": {
17 | "mpvue-loader": "^1.1.2",
18 | "mpvue-webpack-target": "^1.0.0",
19 | "mpvue-template-compiler": "^1.0.11",
20 | "portfinder": "^1.0.13",
21 | "postcss-mpvue-wxss": "^1.0.0",
22 | "prettier": "~1.12.1",
23 | "px2rpx-loader": "^0.1.10",
24 | "babel-core": "^6.22.1",
25 | "glob": "^7.1.2",
26 | "webpack-mpvue-asset-plugin": "^0.1.1",
27 | "relative": "^3.0.2",
28 | "babel-eslint": "^8.2.3",
29 | "babel-loader": "^7.1.1",
30 | "babel-plugin-transform-runtime": "^6.22.0",
31 | "babel-preset-env": "^1.3.2",
32 | "babel-preset-stage-2": "^6.22.0",
33 | "babel-register": "^6.22.0",
34 | "chalk": "^2.4.0",
35 | "connect-history-api-fallback": "^1.3.0",
36 | "copy-webpack-plugin": "^4.5.1",
37 | "css-loader": "^0.28.11",
38 | "cssnano": "^3.10.0",
39 | "eslint": "^4.19.1",
40 | "eslint-friendly-formatter": "^4.0.1",
41 | "eslint-loader": "^2.0.0",
42 | "eslint-plugin-import": "^2.11.0",
43 | "eslint-plugin-node": "^6.0.1",
44 | "eslint-plugin-html": "^4.0.3",
45 | "eslint-config-standard": "^11.0.0",
46 | "eslint-plugin-promise": "^3.4.0",
47 | "eslint-plugin-standard": "^3.0.1",
48 | "eventsource-polyfill": "^0.9.6",
49 | "express": "^4.16.3",
50 | "extract-text-webpack-plugin": "^3.0.2",
51 | "file-loader": "^1.1.11",
52 | "friendly-errors-webpack-plugin": "^1.7.0",
53 | "html-webpack-plugin": "^3.2.0",
54 | "http-proxy-middleware": "^0.18.0",
55 | "webpack-bundle-analyzer": "^2.2.1",
56 | "semver": "^5.3.0",
57 | "shelljs": "^0.8.1",
58 | "uglifyjs-webpack-plugin": "^1.2.5",
59 | "optimize-css-assets-webpack-plugin": "^3.2.0",
60 | "ora": "^2.0.0",
61 | "rimraf": "^2.6.0",
62 | "url-loader": "^1.0.1",
63 | "vue-style-loader": "^4.1.0",
64 | "webpack": "^3.11.0",
65 | "webpack-dev-middleware-hard-disk": "^1.12.0",
66 | "webpack-merge": "^4.1.0",
67 | "postcss-loader": "^2.1.4"
68 | },
69 | "engines": {
70 | "node": ">= 4.0.0",
71 | "npm": ">= 3.0.0"
72 | },
73 | "browserslist": [
74 | "> 1%",
75 | "last 2 versions",
76 | "not ie <= 8"
77 | ]
78 | }
79 |
--------------------------------------------------------------------------------
/echarts/src/pages/bar/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
122 |
123 |
130 |
--------------------------------------------------------------------------------
/echarts/build/webpack.dev.conf.js:
--------------------------------------------------------------------------------
1 | var utils = require('./utils')
2 | var webpack = require('webpack')
3 | var config = require('../config')
4 | var merge = require('webpack-merge')
5 | var baseWebpackConfig = require('./webpack.base.conf')
6 | // var HtmlWebpackPlugin = require('html-webpack-plugin')
7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
8 |
9 | // copy from ./webpack.prod.conf.js
10 | var path = require('path')
11 | var ExtractTextPlugin = require('extract-text-webpack-plugin')
12 | var CopyWebpackPlugin = require('copy-webpack-plugin')
13 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
14 |
15 | // add hot-reload related code to entry chunks
16 | // Object.keys(baseWebpackConfig.entry).forEach(function (name) {
17 | // baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
18 | // })
19 |
20 | module.exports = merge(baseWebpackConfig, {
21 | module: {
22 | rules: utils.styleLoaders({
23 | sourceMap: config.dev.cssSourceMap,
24 | extract: true
25 | })
26 | },
27 | // cheap-module-eval-source-map is faster for development
28 | // devtool: '#cheap-module-eval-source-map',
29 | devtool: '#source-map',
30 | output: {
31 | path: config.build.assetsRoot,
32 | // filename: utils.assetsPath('[name].[chunkhash].js'),
33 | // chunkFilename: utils.assetsPath('[id].[chunkhash].js')
34 | filename: utils.assetsPath('[name].js'),
35 | chunkFilename: utils.assetsPath('[id].js')
36 | },
37 | plugins: [
38 | new webpack.DefinePlugin({
39 | 'process.env': config.dev.env
40 | }),
41 |
42 | // copy from ./webpack.prod.conf.js
43 | // extract css into its own file
44 | new ExtractTextPlugin({
45 | // filename: utils.assetsPath('[name].[contenthash].css')
46 | filename: utils.assetsPath('[name].wxss')
47 | }),
48 | // Compress extracted CSS. We are using this plugin so that possible
49 | // duplicated CSS from different components can be deduped.
50 | new OptimizeCSSPlugin({
51 | cssProcessorOptions: {
52 | safe: true
53 | }
54 | }),
55 | new webpack.optimize.CommonsChunkPlugin({
56 | name: 'common/vendor',
57 | minChunks: function (module, count) {
58 | // any required modules inside node_modules are extracted to vendor
59 | return (
60 | module.resource &&
61 | /\.js$/.test(module.resource) &&
62 | module.resource.indexOf('node_modules') >= 0
63 | ) || count > 1
64 | }
65 | }),
66 | new webpack.optimize.CommonsChunkPlugin({
67 | name: 'common/manifest',
68 | chunks: ['common/vendor']
69 | }),
70 |
71 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
72 | // new webpack.HotModuleReplacementPlugin(),
73 | new webpack.NoEmitOnErrorsPlugin(),
74 | // https://github.com/ampedandwired/html-webpack-plugin
75 | // new HtmlWebpackPlugin({
76 | // filename: 'index.html',
77 | // template: 'index.html',
78 | // inject: true
79 | // }),
80 | new FriendlyErrorsPlugin()
81 | ]
82 | })
83 |
--------------------------------------------------------------------------------
/echarts/build/dev-server.js:
--------------------------------------------------------------------------------
1 | require('./check-versions')()
2 |
3 | var config = require('../config')
4 | if (!process.env.NODE_ENV) {
5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
6 | }
7 |
8 | // var opn = require('opn')
9 | var path = require('path')
10 | var express = require('express')
11 | var webpack = require('webpack')
12 | var proxyMiddleware = require('http-proxy-middleware')
13 | var portfinder = require('portfinder')
14 | var webpackConfig = require('./webpack.dev.conf')
15 |
16 | // default port where dev server listens for incoming traffic
17 | var port = process.env.PORT || config.dev.port
18 | // automatically open browser, if not set will be false
19 | var autoOpenBrowser = !!config.dev.autoOpenBrowser
20 | // Define HTTP proxies to your custom API backend
21 | // https://github.com/chimurai/http-proxy-middleware
22 | var proxyTable = config.dev.proxyTable
23 |
24 | var app = express()
25 | var compiler = webpack(webpackConfig)
26 |
27 | // var devMiddleware = require('webpack-dev-middleware')(compiler, {
28 | // publicPath: webpackConfig.output.publicPath,
29 | // quiet: true
30 | // })
31 |
32 | // var hotMiddleware = require('webpack-hot-middleware')(compiler, {
33 | // log: false,
34 | // heartbeat: 2000
35 | // })
36 | // force page reload when html-webpack-plugin template changes
37 | // compiler.plugin('compilation', function (compilation) {
38 | // compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
39 | // hotMiddleware.publish({ action: 'reload' })
40 | // cb()
41 | // })
42 | // })
43 |
44 | // proxy api requests
45 | Object.keys(proxyTable).forEach(function (context) {
46 | var options = proxyTable[context]
47 | if (typeof options === 'string') {
48 | options = { target: options }
49 | }
50 | app.use(proxyMiddleware(options.filter || context, options))
51 | })
52 |
53 | // handle fallback for HTML5 history API
54 | app.use(require('connect-history-api-fallback')())
55 |
56 | // serve webpack bundle output
57 | // app.use(devMiddleware)
58 |
59 | // enable hot-reload and state-preserving
60 | // compilation error display
61 | // app.use(hotMiddleware)
62 |
63 | // serve pure static assets
64 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
65 | app.use(staticPath, express.static('./static'))
66 |
67 | // var uri = 'http://localhost:' + port
68 |
69 | var _resolve
70 | var readyPromise = new Promise(resolve => {
71 | _resolve = resolve
72 | })
73 |
74 | // console.log('> Starting dev server...')
75 | // devMiddleware.waitUntilValid(() => {
76 | // console.log('> Listening at ' + uri + '\n')
77 | // // when env is testing, don't need open it
78 | // if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
79 | // opn(uri)
80 | // }
81 | // _resolve()
82 | // })
83 |
84 | module.exports = new Promise((resolve, reject) => {
85 | portfinder.basePort = port
86 | portfinder.getPortPromise()
87 | .then(newPort => {
88 | if (port !== newPort) {
89 | console.log(`${port}端口被占用,开启新端口${newPort}`)
90 | }
91 | var server = app.listen(newPort, 'localhost')
92 | // for 小程序的文件保存机制
93 | require('webpack-dev-middleware-hard-disk')(compiler, {
94 | publicPath: webpackConfig.output.publicPath,
95 | quiet: true
96 | })
97 | resolve({
98 | ready: readyPromise,
99 | close: () => {
100 | server.close()
101 | }
102 | })
103 | }).catch(error => {
104 | console.log('没有找到空闲端口,请打开任务管理器杀死进程端口再试', error)
105 | })
106 | })
107 |
--------------------------------------------------------------------------------
/echarts/static/ec-canvas/ec-canvas.js:
--------------------------------------------------------------------------------
1 | import WxCanvas from './wx-canvas';
2 | import * as echarts from './echarts';
3 |
4 | Component({
5 | properties: {
6 | canvasId: {
7 | type: String,
8 | value: 'ec-canvas'
9 | },
10 |
11 | ec: {
12 | type: Object
13 | }
14 | },
15 |
16 | data: {
17 |
18 | },
19 |
20 | ready: function () {
21 | setTimeout(() => {
22 | if (!this.data.ec) {
23 | console.warn('组件需绑定 ec 变量,例:');
25 | return;
26 | }
27 |
28 | if (!this.data.ec.lazyLoad) {
29 | this.init();
30 | }
31 | }, 0)
32 | },
33 |
34 | methods: {
35 | init: function (callback) {
36 | const version = wx.version.version.split('.').map(n => parseInt(n, 10));
37 | const isValid = version[0] > 1 || (version[0] === 1 && version[1] >= 9)
38 | || (version[0] === 1 && version[1] === 9 && version[2] >= 91);
39 | if (!isValid) {
40 | console.error('微信基础库版本过低,需大于等于 1.9.91。'
41 | + '参见:https://github.com/ecomfe/echarts-for-weixin'
42 | + '#%E5%BE%AE%E4%BF%A1%E7%89%88%E6%9C%AC%E8%A6%81%E6%B1%82');
43 | return;
44 | }
45 |
46 | const ctx = wx.createCanvasContext(this.data.canvasId, this);
47 |
48 | const canvas = new WxCanvas(ctx);
49 |
50 | echarts.setCanvasCreator(() => {
51 | return canvas;
52 | });
53 |
54 | var query = wx.createSelectorQuery().in(this);
55 | query.select('.ec-canvas').boundingClientRect(res => {
56 | if (typeof callback === 'function') {
57 | this.chart = callback(canvas, res.width, res.height);
58 | }
59 | else if (this.data.ec && this.data.ec.onInit) {
60 | this.chart = this.data.ec.onInit(canvas, res.width, res.height);
61 | }
62 | else if (this.data.ec && this.data.ec.options) {
63 | const ec = this.data.ec
64 |
65 | function initChart(canvas, width, height) {
66 | const chart = echarts.init(canvas, null, {
67 | width: width,
68 | height: height
69 | });
70 | canvas.setChart(chart);
71 |
72 | chart.setOption(ec.options);
73 | return chart;
74 | }
75 | this.chart = initChart(canvas, res.width, res.height);
76 | }
77 | }).exec();
78 | },
79 |
80 | touchStart(e) {
81 | if (this.chart && e.touches.length > 0) {
82 | var touch = e.touches[0];
83 | this.chart._zr.handler.dispatch('mousedown', {
84 | zrX: touch.x,
85 | zrY: touch.y
86 | });
87 | this.chart._zr.handler.dispatch('mousemove', {
88 | zrX: touch.x,
89 | zrY: touch.y
90 | });
91 | }
92 | },
93 |
94 | touchMove(e) {
95 | if (this.chart && e.touches.length > 0) {
96 | var touch = e.touches[0];
97 | this.chart._zr.handler.dispatch('mousemove', {
98 | zrX: touch.x,
99 | zrY: touch.y
100 | });
101 | }
102 | },
103 |
104 | touchEnd(e) {
105 | if (this.chart) {
106 | const touch = e.changedTouches ? e.changedTouches[0] : {};
107 | this.chart._zr.handler.dispatch('mouseup', {
108 | zrX: touch.x,
109 | zrY: touch.y
110 | });
111 | this.chart._zr.handler.dispatch('click', {
112 | zrX: touch.x,
113 | zrY: touch.y
114 | });
115 | }
116 | }
117 | }
118 | });
119 |
--------------------------------------------------------------------------------
/echarts/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path')
2 | var fs = require('fs')
3 | var utils = require('./utils')
4 | var config = require('../config')
5 | var vueLoaderConfig = require('./vue-loader.conf')
6 | var MpvuePlugin = require('webpack-mpvue-asset-plugin')
7 | var glob = require('glob')
8 | var CopyWebpackPlugin = require('copy-webpack-plugin')
9 | var relative = require('relative')
10 |
11 | function resolve (dir) {
12 | return path.join(__dirname, '..', dir)
13 | }
14 |
15 | function getEntry (rootSrc) {
16 | var map = {};
17 | glob.sync(rootSrc + '/pages/**/main.js')
18 | .forEach(file => {
19 | var key = relative(rootSrc, file).replace('.js', '');
20 | map[key] = file;
21 | })
22 | return map;
23 | }
24 |
25 | const appEntry = { app: resolve('./src/main.js') }
26 | const pagesEntry = getEntry(resolve('./src'), 'pages/**/main.js')
27 | const entry = Object.assign({}, appEntry, pagesEntry)
28 |
29 | module.exports = {
30 | // 如果要自定义生成的 dist 目录里面的文件路径,
31 | // 可以将 entry 写成 {'toPath': 'fromPath'} 的形式,
32 | // toPath 为相对于 dist 的路径, 例:index/demo,则生成的文件地址为 dist/index/demo.js
33 | entry,
34 | target: require('mpvue-webpack-target'),
35 | output: {
36 | path: config.build.assetsRoot,
37 | filename: '[name].js',
38 | publicPath: process.env.NODE_ENV === 'production'
39 | ? config.build.assetsPublicPath
40 | : config.dev.assetsPublicPath
41 | },
42 | resolve: {
43 | extensions: ['.js', '.vue', '.json'],
44 | alias: {
45 | 'vue': 'mpvue',
46 | '@': resolve('src')
47 | },
48 | symlinks: false,
49 | aliasFields: ['mpvue', 'weapp', 'browser'],
50 | mainFields: ['browser', 'module', 'main']
51 | },
52 | module: {
53 | rules: [
54 | {
55 | test: /\.(js|vue)$/,
56 | loader: 'eslint-loader',
57 | enforce: 'pre',
58 | include: [resolve('src'), resolve('test')],
59 | options: {
60 | formatter: require('eslint-friendly-formatter')
61 | }
62 | },
63 | {
64 | test: /\.vue$/,
65 | loader: 'mpvue-loader',
66 | options: vueLoaderConfig
67 | },
68 | {
69 | test: /\.js$/,
70 | include: [resolve('src'), resolve('test')],
71 | use: [
72 | 'babel-loader',
73 | {
74 | loader: 'mpvue-loader',
75 | options: {
76 | checkMPEntry: true
77 | }
78 | },
79 | ]
80 | },
81 | {
82 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
83 | loader: 'url-loader',
84 | options: {
85 | limit: 10000,
86 | name: utils.assetsPath('img/[name].[ext]')
87 | }
88 | },
89 | {
90 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
91 | loader: 'url-loader',
92 | options: {
93 | limit: 10000,
94 | name: utils.assetsPath('media/[name].[ext]')
95 | }
96 | },
97 | {
98 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
99 | loader: 'url-loader',
100 | options: {
101 | limit: 10000,
102 | name: utils.assetsPath('fonts/[name].[ext]')
103 | }
104 | }
105 | ]
106 | },
107 | plugins: [
108 | new MpvuePlugin(),
109 | new CopyWebpackPlugin([{
110 | from: '**/*.json',
111 | to: ''
112 | }], {
113 | context: 'src/'
114 | }),
115 | new CopyWebpackPlugin([
116 | {
117 | from: path.resolve(__dirname, '../static'),
118 | to: path.resolve(__dirname, '../dist/static'),
119 | ignore: ['.*']
120 | }
121 | ])
122 | ]
123 | }
124 |
--------------------------------------------------------------------------------
/echarts/README.md:
--------------------------------------------------------------------------------
1 | # echarts 用法示例
2 |
3 | ## 请注意微信版本要求
4 | 支持微信版本 >= 6.6.3,对应基础库版本 >= 1.9.91。
5 |
6 | 调试的时候,需要在微信开发者工具中,将“详情”下的“调试基础库”设为 1.9.91 及以上版本。
7 |
8 | 发布前,需要在 [https://mp.weixin.qq.com](https://mp.weixin.qq.com) 的“设置”页面,将“基础库最低版本设置”设为 1.9.91。当用户微信版本过低的时候,会提示用户更新。
9 |
10 | ## 具体操作
11 |
12 | 1. 下载 [echarts-for-weixin](https://github.com/ecomfe/echarts-for-weixin) 。
13 |
14 | 2. 把其 `ec-canvas` 目录移动到 mpvue 项目的 `static` 目录下。
15 |
16 | 3. 对 `ec-canvas/ec-canvas.js` 进行小调整,考虑提 pr 到 ec-canvas。
17 |
18 | 修改 ready 为异步获取数据。
19 |
20 | ``` javascript
21 | ready: function () {
22 | // 异步获取
23 | setTimeout(() => {
24 | if (!this.data.ec) {
25 | console.warn('组件需绑定 ec 变量,例:');
27 | return;
28 | }
29 |
30 | if (!this.data.ec.lazyLoad) {
31 | this.init();
32 | }
33 | }, 10)
34 | }
35 | ```
36 |
37 | 为 init 添加接收 options 传参
38 |
39 | ```
40 | var query = wx.createSelectorQuery().in(this);
41 | query.select('.ec-canvas').boundingClientRect(res => {
42 | if (typeof callback === 'function') {
43 | this.chart = callback(canvas, res.width, res.height);
44 | }
45 | else if (this.data.ec && this.data.ec.onInit) {
46 | this.chart = this.data.ec.onInit(canvas, res.width, res.height);
47 | }
48 | else if (this.data.ec && this.data.ec.options) {
49 | // 添加接收 options 传参
50 | const ec = this.data.ec
51 |
52 | function initChart(canvas, width, height) {
53 | const chart = echarts.init(canvas, null, {
54 | width: width,
55 | height: height
56 | });
57 | canvas.setChart(chart);
58 | chart.setOption(ec.options);
59 | return chart;
60 | }
61 | this.chart = initChart(canvas, res.width, res.height);
62 | }
63 | }).exec();
64 | ```
65 |
66 | 4. 创建 `pages/bar` 页面,目录如下:
67 |
68 | ```
69 | .
70 | └── pages
71 | └── bar
72 | ├── index.vue
73 | └── main.js
74 | └── main.json
75 | ```
76 |
77 | 5. 在 `pages/bar/main.js` 中引入微信小程序的自定义组件
78 |
79 | ``` javascript
80 | import Vue from 'vue'
81 | import App from './index'
82 |
83 | const app = new Vue(App)
84 | app.$mount()
85 | ```
86 |
87 | 6. 在 `pages/bar/main.json` 中引入微信小程序的自定义组件
88 |
89 | ``` json
90 | {
91 | "usingComponents": {
92 | "ec-canvas": "../../../static/ec-canvas/ec-canvas"
93 | }
94 | }
95 | ```
96 |
97 | 7. 在 `pages/bar/index.vue` 中添加 options、template 等相关配置
98 |
99 | ```
100 |
101 |
106 |
107 |
108 |
125 |
126 |
133 | ```
134 |
135 | 最终效果:
136 |
137 | 
138 |
139 | 如果报错,试试开启 ES6 转 ES5 或者重启开发者工具试试。
140 |
141 | ## Build Setup
142 |
143 | ``` bash
144 | # install dependencies
145 | npm install
146 |
147 | # serve with hot reload at localhost:8080
148 | npm run dev
149 |
150 | # build for production with minification
151 | npm run build
152 |
153 | # build for production and view the bundle analyzer report
154 | npm run build --report
155 | ```
156 |
157 | For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
158 |
--------------------------------------------------------------------------------
/echarts/build/webpack.prod.conf.js:
--------------------------------------------------------------------------------
1 | var path = require('path')
2 | var utils = require('./utils')
3 | var webpack = require('webpack')
4 | var config = require('../config')
5 | var merge = require('webpack-merge')
6 | var baseWebpackConfig = require('./webpack.base.conf')
7 | var UglifyJsPlugin = require('uglifyjs-webpack-plugin')
8 | var CopyWebpackPlugin = require('copy-webpack-plugin')
9 | // var HtmlWebpackPlugin = require('html-webpack-plugin')
10 | var ExtractTextPlugin = require('extract-text-webpack-plugin')
11 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
12 |
13 | var env = config.build.env
14 |
15 | var webpackConfig = merge(baseWebpackConfig, {
16 | module: {
17 | rules: utils.styleLoaders({
18 | sourceMap: config.build.productionSourceMap,
19 | extract: true
20 | })
21 | },
22 | devtool: config.build.productionSourceMap ? '#source-map' : false,
23 | output: {
24 | path: config.build.assetsRoot,
25 | // filename: utils.assetsPath('[name].[chunkhash].js'),
26 | // chunkFilename: utils.assetsPath('[id].[chunkhash].js')
27 | filename: utils.assetsPath('[name].js'),
28 | chunkFilename: utils.assetsPath('[id].js')
29 | },
30 | plugins: [
31 | // http://vuejs.github.io/vue-loader/en/workflow/production.html
32 | new webpack.DefinePlugin({
33 | 'process.env': env
34 | }),
35 | new UglifyJsPlugin({
36 | sourceMap: true
37 | }),
38 | // extract css into its own file
39 | new ExtractTextPlugin({
40 | // filename: utils.assetsPath('[name].[contenthash].css')
41 | filename: utils.assetsPath('[name].wxss')
42 | }),
43 | // Compress extracted CSS. We are using this plugin so that possible
44 | // duplicated CSS from different components can be deduped.
45 | new OptimizeCSSPlugin({
46 | cssProcessorOptions: {
47 | safe: true
48 | }
49 | }),
50 | // generate dist index.html with correct asset hash for caching.
51 | // you can customize output by editing /index.html
52 | // see https://github.com/ampedandwired/html-webpack-plugin
53 | // new HtmlWebpackPlugin({
54 | // filename: config.build.index,
55 | // template: 'index.html',
56 | // inject: true,
57 | // minify: {
58 | // removeComments: true,
59 | // collapseWhitespace: true,
60 | // removeAttributeQuotes: true
61 | // // more options:
62 | // // https://github.com/kangax/html-minifier#options-quick-reference
63 | // },
64 | // // necessary to consistently work with multiple chunks via CommonsChunkPlugin
65 | // chunksSortMode: 'dependency'
66 | // }),
67 | // keep module.id stable when vender modules does not change
68 | new webpack.HashedModuleIdsPlugin(),
69 | // split vendor js into its own file
70 | new webpack.optimize.CommonsChunkPlugin({
71 | name: 'common/vendor',
72 | minChunks: function (module, count) {
73 | // any required modules inside node_modules are extracted to vendor
74 | return (
75 | module.resource &&
76 | /\.js$/.test(module.resource) &&
77 | module.resource.indexOf('node_modules') >= 0
78 | ) || count > 1
79 | }
80 | }),
81 | // extract webpack runtime and module manifest to its own file in order to
82 | // prevent vendor hash from being updated whenever app bundle is updated
83 | new webpack.optimize.CommonsChunkPlugin({
84 | name: 'common/manifest',
85 | chunks: ['common/vendor']
86 | })
87 | ]
88 | })
89 |
90 | // if (config.build.productionGzip) {
91 | // var CompressionWebpackPlugin = require('compression-webpack-plugin')
92 |
93 | // webpackConfig.plugins.push(
94 | // new CompressionWebpackPlugin({
95 | // asset: '[path].gz[query]',
96 | // algorithm: 'gzip',
97 | // test: new RegExp(
98 | // '\\.(' +
99 | // config.build.productionGzipExtensions.join('|') +
100 | // ')$'
101 | // ),
102 | // threshold: 10240,
103 | // minRatio: 0.8
104 | // })
105 | // )
106 | // }
107 |
108 | if (config.build.bundleAnalyzerReport) {
109 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
110 | webpackConfig.plugins.push(new BundleAnalyzerPlugin())
111 | }
112 |
113 | module.exports = webpackConfig
114 |
--------------------------------------------------------------------------------