Authored by lea guo

赠加babel-plugin-lodash插件

@@ -23,7 +23,7 @@ import RecommendGoods from "./components/recommend-goods"; @@ -23,7 +23,7 @@ import RecommendGoods from "./components/recommend-goods";
23 import RecommendFreeGoods from "./components/recommend-free-goods"; 23 import RecommendFreeGoods from "./components/recommend-free-goods";
24 import { createNamespacedHelpers } from "vuex"; 24 import { createNamespacedHelpers } from "vuex";
25 25
26 -const { mapState } = createNamespacedHelpers("freeCharge"); 26 +const { mapState, mapActions } = createNamespacedHelpers("zeroHelp");
27 27
28 export default { 28 export default {
29 components: { 29 components: {
@@ -38,7 +38,13 @@ export default { @@ -38,7 +38,13 @@ export default {
38 "http://img10.static.yhbimg.com/yhb-img01/2019/08/20/17/01bb10aa4f373016cc5e7963b1d6c1182f.jpg" 38 "http://img10.static.yhbimg.com/yhb-img01/2019/08/20/17/01bb10aa4f373016cc5e7963b1d6c1182f.jpg"
39 }; 39 };
40 }, 40 },
41 - computed: {} 41 + computed: {},
  42 + mounted() {
  43 + this.fetchPoolGoods();
  44 + },
  45 + methods: {
  46 + ...mapActions(["fetchPoolGoods"])
  47 + }
42 }; 48 };
43 </script> 49 </script>
44 50
@@ -17,7 +17,7 @@ export default function() { @@ -17,7 +17,7 @@ export default function() {
17 pageSize: 10, 17 pageSize: 10,
18 total: 0, 18 total: 0,
19 page: 0, 19 page: 0,
20 - filterId: 0 20 + filterId: 0,
21 }, 21 },
22 use: { 22 use: {
23 couponList: [], 23 couponList: [],
@@ -25,7 +25,7 @@ export default function() { @@ -25,7 +25,7 @@ export default function() {
25 pageSize: 10, 25 pageSize: 10,
26 total: 0, 26 total: 0,
27 page: 0, 27 page: 0,
28 - filterId: 0 28 + filterId: 0,
29 }, 29 },
30 overtime: { 30 overtime: {
31 couponList: [], 31 couponList: [],
@@ -33,13 +33,13 @@ export default function() { @@ -33,13 +33,13 @@ export default function() {
33 pageSize: 10, 33 pageSize: 10,
34 total: 0, 34 total: 0,
35 page: 0, 35 page: 0,
36 - filterId: 0  
37 - } 36 + filterId: 0,
  37 + },
38 }, 38 },
39 num: { 39 num: {
40 notuse: 0, 40 notuse: 0,
41 use: 0, 41 use: 0,
42 - overtime: 0 42 + overtime: 0,
43 }, 43 },
44 ufoList: [], 44 ufoList: [],
45 filterList: [], 45 filterList: [],
@@ -48,7 +48,11 @@ export default function() { @@ -48,7 +48,11 @@ export default function() {
48 mutations, 48 mutations,
49 getters: { 49 getters: {
50 getNum(state) { 50 getNum(state) {
51 - return [handleNum(state.num.notuse), handleNum(state.num.use), handleNum(state.num.overtime)]; 51 + return [
  52 + handleNum(state.num.notuse),
  53 + handleNum(state.num.use),
  54 + handleNum(state.num.overtime),
  55 + ];
52 }, 56 },
53 getNotUseList(state) { 57 getNotUseList(state) {
54 return state.yohoList.notuse.couponList; 58 return state.yohoList.notuse.couponList;
@@ -59,6 +63,6 @@ export default function() { @@ -59,6 +63,6 @@ export default function() {
59 getOvertimeList(state) { 63 getOvertimeList(state) {
60 return state.yohoList.overtime.couponList; 64 return state.yohoList.overtime.couponList;
61 }, 65 },
62 - } 66 + },
63 }; 67 };
64 } 68 }
  1 +export const FETCH_ZERO_HELP_OTHER_GOODS = 'FETCH_ZERO_HELP_OTHER_GOODS';
  2 +export const FETCH_POOL_GOODS = 'FETCH_POOL_GOODS';
  3 +export const FETCH_ZERO_HELP_COMMAND = 'FETCH_ZERO_HELP_COMMAND';
  4 +export const FETCH_INIT = 'FETCH_INIT';
  5 +export const IS_LOADING = 'IS_LOADING';
  6 +const productPool = 730;
  7 +
  8 +import { isArray, isEmpty } from 'lodash';
  9 +
1 export default { 10 export default {
2 namespaced: true, 11 namespaced: true,
3 state: { 12 state: {
4 - recommendGoods: [],  
5 - recommendFreeChargeGoods: [], 13 + isLoading: false,
  14 + poolGoodsInfo: {
  15 + page: 0,
  16 + pageSize: 10,
  17 + total: 0,
  18 + goodsList: [],
  19 + },
  20 + recommendFreeChargeGoods: {},
6 }, 21 },
7 getters: {}, 22 getters: {},
8 actions: { 23 actions: {
9 - async fetchRecommendGoods() {}, 24 + async init({ commit }) {
  25 + commit(IS_LOADING, true);
  26 + commit('FETCH_INIT');
  27 + },
  28 +
  29 + // 获取资源池商品
  30 + async fetchPoolGoods({ commit, state: { poolGoodsInfo } }) {
  31 + let { total, pageSize, page } = poolGoodsInfo;
  32 +
  33 + if (page * pageSize > total) {
  34 + return;
  35 + }
  36 +
  37 + page++;
  38 +
  39 + let res = await this.$api.get('/api/zero/help/poll/productList', {
  40 + page,
  41 + limit: pageSize,
  42 + productPool,
  43 + });
  44 +
  45 + if (res.code !== 200) {
  46 + commit(IS_LOADING, false);
  47 + return;
  48 + }
  49 +
  50 + /**
  51 + * 数据格式兼容
  52 + * res: {
  53 + * code: 200,
  54 + * data: [] | {total, page_total, page_size, page, product_list}
  55 + * }
  56 + * 无数据返回 []
  57 + */
  58 + if (isArray(res.data) && isEmpty(res)) {
  59 + res = { ...res, data: { product_list: [], page } };
  60 + }
  61 + commit(FETCH_POOL_GOODS, res);
  62 + },
  63 + async fetchZeroHelpOtherGoods() {},
  64 + async fetchZeroHelpCommand() {},
  65 + async fetchZeroHelpInfo() {
  66 + // const res = await this.$api.get('')
  67 + },
  68 + },
  69 + mutations: {
  70 + [FETCH_INIT](state, data) {
  71 + state.recommendGoods = data;
  72 + },
  73 + [IS_LOADING](state, status = false) {
  74 + state.isLoading = status;
  75 + },
  76 + // eslint-disable-next-line no-unused-vars
  77 + [FETCH_POOL_GOODS]({ poolGoodsInfo }, res) {
  78 + poolGoodsInfo = { ...poolGoodsInfo, res };
  79 + },
10 }, 80 },
11 - mutations: {},  
12 }; 81 };
1 module.exports = { 1 module.exports = {
2 presets: [ 2 presets: [
3 - ['@babel/preset-env', {  
4 - modules: false,  
5 - useBuiltIns: 'usage'  
6 - }] 3 + [
  4 + '@babel/preset-env',
  5 + {
  6 + modules: false,
  7 + useBuiltIns: 'usage',
  8 + },
  9 + ],
7 ], 10 ],
8 sourceType: 'unambiguous', 11 sourceType: 'unambiguous',
9 plugins: [ 12 plugins: [
10 'transform-vue-jsx', 13 'transform-vue-jsx',
11 '@babel/transform-async-to-generator', 14 '@babel/transform-async-to-generator',
12 '@babel/proposal-object-rest-spread', 15 '@babel/proposal-object-rest-spread',
13 - '@babel/syntax-dynamic-import'  
14 - ] 16 + '@babel/syntax-dynamic-import',
  17 + 'lodash',
  18 + ],
15 }; 19 };
@@ -4,6 +4,8 @@ const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin'); @@ -4,6 +4,8 @@ const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
4 var PostCompilePlugin = require('webpack-post-compile-plugin'); 4 var PostCompilePlugin = require('webpack-post-compile-plugin');
5 var TransformModulesPlugin = require('webpack-transform-modules-plugin'); 5 var TransformModulesPlugin = require('webpack-transform-modules-plugin');
6 const VueLoaderPlugin = require('vue-loader/lib/plugin'); 6 const VueLoaderPlugin = require('vue-loader/lib/plugin');
  7 +var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
  8 +
7 const pkg = require('../package.json'); 9 const pkg = require('../package.json');
8 const isProd = process.env.NODE_ENV === 'production'; 10 const isProd = process.env.NODE_ENV === 'production';
9 const distDir = path.join(__dirname, `../dist/statics/${pkg.name}`); 11 const distDir = path.join(__dirname, `../dist/statics/${pkg.name}`);
@@ -12,25 +14,21 @@ function resolve(dir) { @@ -12,25 +14,21 @@ function resolve(dir) {
12 return path.join(__dirname, '..', dir); 14 return path.join(__dirname, '..', dir);
13 } 15 }
14 16
15 -  
16 const webpackConfig = { 17 const webpackConfig = {
17 mode: isProd ? 'production' : 'development', 18 mode: isProd ? 'production' : 'development',
18 output: { 19 output: {
19 filename: 'static/js/[name].[chunkhash].js', 20 filename: 'static/js/[name].[chunkhash].js',
20 path: distDir, 21 path: distDir,
21 chunkFilename: 'static/js/[name].[chunkhash].js', 22 chunkFilename: 'static/js/[name].[chunkhash].js',
22 - publicPath: isProd ? '//cdn.yoho.cn/yoho-app-web/' : '/' 23 + publicPath: isProd ? '//cdn.yoho.cn/yoho-app-web/' : '/',
23 }, 24 },
24 resolve: { 25 resolve: {
25 extensions: ['.js', '.vue', '.json'], 26 extensions: ['.js', '.vue', '.json'],
26 alias: { 27 alias: {
27 vue$: 'vue/dist/vue.runtime.esm.js', 28 vue$: 'vue/dist/vue.runtime.esm.js',
28 - 'lottie-web': 'lottie-web/build/player/lottie_light.min.js' 29 + 'lottie-web': 'lottie-web/build/player/lottie_light.min.js',
29 }, 30 },
30 - modules: [  
31 - path.join(__dirname, '../apps'),  
32 - 'node_modules'  
33 - ] 31 + modules: [path.join(__dirname, '../apps'), 'node_modules'],
34 }, 32 },
35 module: { 33 module: {
36 rules: [ 34 rules: [
@@ -40,20 +38,20 @@ const webpackConfig = { @@ -40,20 +38,20 @@ const webpackConfig = {
40 loader: 'vue-loader', 38 loader: 'vue-loader',
41 options: { 39 options: {
42 extractCSS: isProd, 40 extractCSS: isProd,
43 - } 41 + },
44 }, 42 },
45 }, 43 },
46 { 44 {
47 resourceQuery: /blockType=client/, 45 resourceQuery: /blockType=client/,
48 use: 'babel-loader', 46 use: 'babel-loader',
49 - exclude: /node_modules/ 47 + exclude: /node_modules/,
50 }, 48 },
51 { 49 {
52 test: /\.js$/, 50 test: /\.js$/,
53 use: 'babel-loader', 51 use: 'babel-loader',
54 - include: [resolve('apps'), /cube-ui/] 52 + include: [resolve('apps'), /cube-ui/],
55 }, 53 },
56 - ] 54 + ],
57 }, 55 },
58 plugins: [ 56 plugins: [
59 new webpack.HashedModuleIdsPlugin(), 57 new webpack.HashedModuleIdsPlugin(),
@@ -61,9 +59,8 @@ const webpackConfig = { @@ -61,9 +59,8 @@ const webpackConfig = {
61 new PostCompilePlugin(), 59 new PostCompilePlugin(),
62 new TransformModulesPlugin(), 60 new TransformModulesPlugin(),
63 new VueLoaderPlugin(), 61 new VueLoaderPlugin(),
64 - ] 62 + new LodashModuleReplacementPlugin(),
  63 + ],
65 }; 64 };
66 65
67 -  
68 -  
69 module.exports = webpackConfig; 66 module.exports = webpackConfig;
@@ -24,10 +24,6 @@ @@ -24,10 +24,6 @@
24 "cube-ui": { 24 "cube-ui": {
25 "transform": "cube-ui/src/modules/${member}", 25 "transform": "cube-ui/src/modules/${member}",
26 "kebabCase": true 26 "kebabCase": true
27 - },  
28 - "lodash": {  
29 - "transform": "lodash/${member}",  
30 - "kebabCase": true  
31 } 27 }
32 }, 28 },
33 "dependencies": { 29 "dependencies": {
@@ -82,6 +78,7 @@ @@ -82,6 +78,7 @@
82 "babel-eslint": "^10.0.1", 78 "babel-eslint": "^10.0.1",
83 "babel-loader": "^8.0.4", 79 "babel-loader": "^8.0.4",
84 "babel-plugin-import": "^1.11.0", 80 "babel-plugin-import": "^1.11.0",
  81 + "babel-plugin-lodash": "^3.3.4",
85 "babel-plugin-syntax-jsx": "^6.18.0", 82 "babel-plugin-syntax-jsx": "^6.18.0",
86 "babel-plugin-transform-imports": "^1.5.1", 83 "babel-plugin-transform-imports": "^1.5.1",
87 "babel-plugin-transform-vue-jsx": "^3.7.0", 84 "babel-plugin-transform-vue-jsx": "^3.7.0",
@@ -95,6 +92,7 @@ @@ -95,6 +92,7 @@
95 "html-webpack-plugin": "^3.2.0", 92 "html-webpack-plugin": "^3.2.0",
96 "husky": "^1.2.0", 93 "husky": "^1.2.0",
97 "ignore-loader": "^0.1.2", 94 "ignore-loader": "^0.1.2",
  95 + "lodash-webpack-plugin": "^0.11.5",
98 "memory-fs": "^0.4.1", 96 "memory-fs": "^0.4.1",
99 "mini-css-extract-plugin": "^0.5.0", 97 "mini-css-extract-plugin": "^0.5.0",
100 "node-sass": "^4.11.0", 98 "node-sass": "^4.11.0",
@@ -128,7 +128,7 @@ @@ -128,7 +128,7 @@
128 dependencies: 128 dependencies:
129 "@babel/types" "^7.0.0" 129 "@babel/types" "^7.0.0"
130 130
131 -"@babel/helper-module-imports@^7.0.0": 131 +"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.0.0-beta.49":
132 version "7.0.0" 132 version "7.0.0"
133 resolved "http://npm.yohops.com/@babel%2fhelper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d" 133 resolved "http://npm.yohops.com/@babel%2fhelper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d"
134 dependencies: 134 dependencies:
@@ -613,6 +613,15 @@ @@ -613,6 +613,15 @@
613 lodash "^4.17.10" 613 lodash "^4.17.10"
614 to-fast-properties "^2.0.0" 614 to-fast-properties "^2.0.0"
615 615
  616 +"@babel/types@^7.0.0-beta.49":
  617 + version "7.5.5"
  618 + resolved "http://npm.yohops.com/@babel%2ftypes/-/types-7.5.5.tgz#97b9f728e182785909aa4ab56264f090a028d18a"
  619 + integrity sha1-l7n3KOGCeFkJqkq1YmTwkKAo0Yo=
  620 + dependencies:
  621 + esutils "^2.0.2"
  622 + lodash "^4.17.13"
  623 + to-fast-properties "^2.0.0"
  624 +
616 "@babel/types@^7.2.2": 625 "@babel/types@^7.2.2":
617 version "7.2.2" 626 version "7.2.2"
618 resolved "http://npm.yohops.com/@babel%2ftypes/-/types-7.2.2.tgz#44e10fc24e33af524488b716cdaee5360ea8ed1e" 627 resolved "http://npm.yohops.com/@babel%2ftypes/-/types-7.2.2.tgz#44e10fc24e33af524488b716cdaee5360ea8ed1e"
@@ -1075,6 +1084,17 @@ babel-plugin-import@^1.11.0: @@ -1075,6 +1084,17 @@ babel-plugin-import@^1.11.0:
1075 "@babel/helper-module-imports" "^7.0.0" 1084 "@babel/helper-module-imports" "^7.0.0"
1076 "@babel/runtime" "^7.0.0" 1085 "@babel/runtime" "^7.0.0"
1077 1086
  1087 +babel-plugin-lodash@^3.3.4:
  1088 + version "3.3.4"
  1089 + resolved "http://npm.yohops.com/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz#4f6844358a1340baed182adbeffa8df9967bc196"
  1090 + integrity sha1-T2hENYoTQLrtGCrb7/qN+ZZ7wZY=
  1091 + dependencies:
  1092 + "@babel/helper-module-imports" "^7.0.0-beta.49"
  1093 + "@babel/types" "^7.0.0-beta.49"
  1094 + glob "^7.1.1"
  1095 + lodash "^4.17.10"
  1096 + require-package-name "^2.0.1"
  1097 +
1078 babel-plugin-syntax-jsx@^6.18.0: 1098 babel-plugin-syntax-jsx@^6.18.0:
1079 version "6.18.0" 1099 version "6.18.0"
1080 resolved "http://npm.yohops.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946" 1100 resolved "http://npm.yohops.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
@@ -3181,6 +3201,18 @@ glob@^7.0.5: @@ -3181,6 +3201,18 @@ glob@^7.0.5:
3181 once "^1.3.0" 3201 once "^1.3.0"
3182 path-is-absolute "^1.0.0" 3202 path-is-absolute "^1.0.0"
3183 3203
  3204 +glob@^7.1.1:
  3205 + version "7.1.4"
  3206 + resolved "http://npm.yohops.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
  3207 + integrity sha1-qmCKL2xXetNX4a5aXCbZqNGWklU=
  3208 + dependencies:
  3209 + fs.realpath "^1.0.0"
  3210 + inflight "^1.0.4"
  3211 + inherits "2"
  3212 + minimatch "^3.0.4"
  3213 + once "^1.3.0"
  3214 + path-is-absolute "^1.0.0"
  3215 +
3184 global-dirs@^0.1.0: 3216 global-dirs@^0.1.0:
3185 version "0.1.1" 3217 version "0.1.1"
3186 resolved "http://npm.yohops.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445" 3218 resolved "http://npm.yohops.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445"
@@ -4287,6 +4319,13 @@ locate-path@^3.0.0: @@ -4287,6 +4319,13 @@ locate-path@^3.0.0:
4287 p-locate "^3.0.0" 4319 p-locate "^3.0.0"
4288 path-exists "^3.0.0" 4320 path-exists "^3.0.0"
4289 4321
  4322 +lodash-webpack-plugin@^0.11.5:
  4323 + version "0.11.5"
  4324 + resolved "http://npm.yohops.com/lodash-webpack-plugin/-/lodash-webpack-plugin-0.11.5.tgz#c4bd064b4f561c3f823fa5982bdeb12c475390b9"
  4325 + integrity sha1-xL0GS09WHD+CP6WYK96xLEdTkLk=
  4326 + dependencies:
  4327 + lodash "^4.17.4"
  4328 +
4290 lodash._baseclone@~4.5.0: 4329 lodash._baseclone@~4.5.0:
4291 version "4.5.7" 4330 version "4.5.7"
4292 resolved "http://npm.yohops.com/lodash._baseclone/-/lodash._baseclone-4.5.7.tgz#ce42ade08384ef5d62fa77c30f61a46e686f8434" 4331 resolved "http://npm.yohops.com/lodash._baseclone/-/lodash._baseclone-4.5.7.tgz#ce42ade08384ef5d62fa77c30f61a46e686f8434"
@@ -4362,6 +4401,11 @@ lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3, @@ -4362,6 +4401,11 @@ lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3,
4362 version "4.17.11" 4401 version "4.17.11"
4363 resolved "http://npm.yohops.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" 4402 resolved "http://npm.yohops.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
4364 4403
  4404 +lodash@^4.17.13:
  4405 + version "4.17.15"
  4406 + resolved "http://npm.yohops.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
  4407 + integrity sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg=
  4408 +
4365 log-symbols@^2.0.0: 4409 log-symbols@^2.0.0:
4366 version "2.2.0" 4410 version "2.2.0"
4367 resolved "http://npm.yohops.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a" 4411 resolved "http://npm.yohops.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"
@@ -6154,6 +6198,11 @@ require-main-filename@^1.0.1: @@ -6154,6 +6198,11 @@ require-main-filename@^1.0.1:
6154 version "1.0.1" 6198 version "1.0.1"
6155 resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" 6199 resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"
6156 6200
  6201 +require-package-name@^2.0.1:
  6202 + version "2.0.1"
  6203 + resolved "http://npm.yohops.com/require-package-name/-/require-package-name-2.0.1.tgz#c11e97276b65b8e2923f75dabf5fb2ef0c3841b9"
  6204 + integrity sha1-wR6XJ2tluOKSP3Xav1+y7ww4Qbk=
  6205 +
6157 require-uncached@^1.0.3: 6206 require-uncached@^1.0.3:
6158 version "1.0.3" 6207 version "1.0.3"
6159 resolved "http://npm.yohops.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3" 6208 resolved "http://npm.yohops.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3"