xuqiang 4 سال پیش
والد
کامیت
d51fe99150
16فایلهای تغییر یافته به همراه703 افزوده شده و 874 حذف شده
  1. 21 21
      .eslintrc.js
  2. 6 0
      .prettierrc.js
  3. 76 76
      megalo.config.js
  4. 53 53
      src/App.vue
  5. 1 1
      src/components/add.vue
  6. 73 73
      src/main.js
  7. 55 55
      src/mixins/allPage.js
  8. 39 39
      src/mixins/cardPage.js
  9. 117 117
      src/mixins/common.js
  10. 0 165
      src/mixins/plugins/http.js
  11. 22 22
      src/mixins/store.js
  12. 8 13
      src/pages/Home.vue
  13. 1 1
      src/pages/news.vue
  14. 22 27
      src/pages/vuex/vuex.vue
  15. 155 157
      src/plugins/http.js
  16. 54 54
      src/store/index.js

+ 21 - 21
.eslintrc.js

@@ -1,22 +1,22 @@
 module.exports = {
-  root: true,
-  env: {
-    node: true,
-  },
-  extends: ['@megalo/standard', '@vue/prettier'],
-  rules: {
-    'no-console': 'off',
-    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
-    'no-unused-vars': 'off',
-    'no-empty': ['error', { allowEmptyCatch: true }],
-    'prettier/prettier': ['error'],
-  },
-  // parserOptions: {
-  //     parser: 'babel-eslint'
-  // },
-  globals: {
-    Chart: true,
-    AMap: true,
-    FontAwesome: true,
-  },
-}
+    root: true,
+    env: {
+        node: true
+    },
+    extends: ['@megalo/standard', '@vue/prettier'],
+    rules: {
+        'no-console': 'off',
+        'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
+        'no-unused-vars': 'off',
+        'no-empty': ['error', { allowEmptyCatch: true }],
+        'prettier/prettier': ['error']
+    },
+    // parserOptions: {
+    //     parser: 'babel-eslint'
+    // },
+    globals: {
+        Chart: true,
+        AMap: true,
+        FontAwesome: true
+    }
+};

+ 6 - 0
.prettierrc.js

@@ -0,0 +1,6 @@
+module.exports = {
+    printWidth: 120,
+    singleQuote: true,
+    tabWidth: 4,
+    endOfLine: 'auto'
+};

+ 76 - 76
megalo.config.js

@@ -1,82 +1,82 @@
-const path = require("path");
+const path = require('path');
 module.exports = {
-  // 构件生产模式时是否生成source map(仅在process.env.NODE_ENV === 'production' 时该选项生效)
-  productionSourceMap: false,
+    // 构件生产模式时是否生成source map(仅在process.env.NODE_ENV === 'production' 时该选项生效)
+    productionSourceMap: false,
 
-  // 开启eslint格式化代码
-  lintOnSave: true,
+    // 开启eslint格式化代码
+    lintOnSave: true,
 
-  configureWebpack: config => {
-    // 你可以在这里粗放的修改webpack的配置并返回
-    console.log("configureWebpack执行了");
-    return config;
-  },
-  chainWebpack: chainConfig => {
-    chainConfig.plugin("copy-webpack-plugin").tap(args => {
-      args[0].push({
-        context: path.resolve("src"),
-        from: path.resolve("project.config.json"),
-        to: path.resolve(`dist-${process.env.PLATFORM}/project.config.json`)
-      });
-      args[0].push({
-        context: path.resolve("src"),
-        from: path.resolve("src/vant"),
-        to: path.resolve(`dist-${process.env.PLATFORM}/vant`)
-      });
-      // let str = /usingComponents:[\W](\{[\w\W]+?\})/
-      //     .exec(fs.readFileSync('src/main.js').toString())[1]
-      //     .replace(/[\s]/g, '')
-      //     .replace(/'/g, '"');
-      // console.log(str);
-      // let components = JSON.parse(str);
-      // Object.keys(components).forEach(key => {
-      //     let from = path.resolve('src', components[key].replace(/^\//, ''), '../');
-      //     let to = path.resolve(`dist-${process.env.PLATFORM}`, components[key].replace(/^\//, ''), '../');
-      //     args[0].push({
-      //         context: path.resolve('src'),
-      //         from,
-      //         to
-      //     });
-      //     console.log(from, to);
-      // });
-      return args;
-    });
-    chainConfig.module
-      .rule("less")
-      .test(/\.less$/)
-      .use("style-resources-loader")
-      .loader("style-resources-loader")
-      .options({
-        patterns: [path.resolve(__dirname, "./src/styles/common.less")]
-      })
-      .end();
-    // 你可以在这里通过 https://github.com/neutrinojs/webpack-chain 来精细的修改webpack配置
-    // console.log('chainWebpack执行了', chainConfig.toString())
-  },
-  // 原生小程序组件存放目录,默认为src/native
-  // 如果你有多个平台的原生组件,你应当在此目录下再新建几个子文件夹,我们约定,子文件夹名和平台的名字一致:
-  // 微信小程序组件则命名为 'wechat',支付宝为'alipay', 百度为 'swan'
-  // 如果只有一个平台,则无需再新建子文件夹
-  nativeDir: "/src/native",
+    configureWebpack: config => {
+        // 你可以在这里粗放的修改webpack的配置并返回
+        console.log('configureWebpack执行了');
+        return config;
+    },
+    chainWebpack: chainConfig => {
+        chainConfig.plugin('copy-webpack-plugin').tap(args => {
+            args[0].push({
+                context: path.resolve('src'),
+                from: path.resolve('project.config.json'),
+                to: path.resolve(`dist-${process.env.PLATFORM}/project.config.json`)
+            });
+            args[0].push({
+                context: path.resolve('src'),
+                from: path.resolve('src/vant'),
+                to: path.resolve(`dist-${process.env.PLATFORM}/vant`)
+            });
+            // let str = /usingComponents:[\W](\{[\w\W]+?\})/
+            //     .exec(fs.readFileSync('src/main.js').toString())[1]
+            //     .replace(/[\s]/g, '')
+            //     .replace(/'/g, '"');
+            // console.log(str);
+            // let components = JSON.parse(str);
+            // Object.keys(components).forEach(key => {
+            //     let from = path.resolve('src', components[key].replace(/^\//, ''), '../');
+            //     let to = path.resolve(`dist-${process.env.PLATFORM}`, components[key].replace(/^\//, ''), '../');
+            //     args[0].push({
+            //         context: path.resolve('src'),
+            //         from,
+            //         to
+            //     });
+            //     console.log(from, to);
+            // });
+            return args;
+        });
+        chainConfig.module
+            .rule('less')
+            .test(/\.less$/)
+            .use('style-resources-loader')
+            .loader('style-resources-loader')
+            .options({
+                patterns: [path.resolve(__dirname, './src/styles/common.less')]
+            })
+            .end();
+        // 你可以在这里通过 https://github.com/neutrinojs/webpack-chain 来精细的修改webpack配置
+        // console.log('chainWebpack执行了', chainConfig.toString())
+    },
+    // 原生小程序组件存放目录,默认为src/native
+    // 如果你有多个平台的原生组件,你应当在此目录下再新建几个子文件夹,我们约定,子文件夹名和平台的名字一致:
+    // 微信小程序组件则命名为 'wechat',支付宝为'alipay', 百度为 'swan'
+    // 如果只有一个平台,则无需再新建子文件夹
+    nativeDir: '/src/native',
 
-  css: {
-    loaderOptions: {
-      css: {
-        // https://github.com/webpack-contrib/css-loader#options
-      },
-      less: {
-        // https://github.com/webpack-contrib/less-loader
-      },
-      sass: {
-        // https://github.com/webpack-contrib/sass-loader
-      },
-      stylus: {
-        // https://github.com/shama/stylus-loader
-      },
-      // https://github.com/megalojs/megalo-px2rpx-loader
-      px2rpx: {
-        rpxUnit: 0.5
-      }
+    css: {
+        loaderOptions: {
+            css: {
+                // https://github.com/webpack-contrib/css-loader#options
+            },
+            less: {
+                // https://github.com/webpack-contrib/less-loader
+            },
+            sass: {
+                // https://github.com/webpack-contrib/sass-loader
+            },
+            stylus: {
+                // https://github.com/shama/stylus-loader
+            },
+            // https://github.com/megalojs/megalo-px2rpx-loader
+            px2rpx: {
+                rpxUnit: 0.5
+            }
+        }
     }
-  }
 };

+ 53 - 53
src/App.vue

@@ -1,63 +1,63 @@
 <script>
 export default {
-  onLaunch(options) {
-    wx.login({
-      success: res => {
-        console.log(res);
-        this.$http
-          .post("/auth/maLogin", { code: res.code })
-          .then(res => {
-            this.$http.setToken(res.token);
-            // this.$store.commit("setSessionKey", res.sessionKey);
-            this.$store
-              .dispatch("getUserInfo")
-              .then(() => {
-                this.globalData.initialize = true;
-                console.log(this.globalData);
-                if (this.globalData.initializeCallback) {
-                  this.globalData.initializeCallback();
-                }
-              })
-              .catch(() => {
-                this.globalData.initialize = true;
-              });
-          })
-          .catch(e => {
-            console.log(e);
-          });
-      }
-    });
-    // wx.getSystemInfo({
-    //   success: res => {
-    //     console.log(res);
-    //     this.$store.commit("setSystemInfo", res);
-    //   }
-    // });
+    onLaunch(options) {
+        wx.login({
+            success: res => {
+                console.log(res);
+                this.$http
+                    .post('/auth/maLogin', { code: res.code })
+                    .then(res => {
+                        this.$http.setToken(res.token);
+                        // this.$store.commit("setSessionKey", res.sessionKey);
+                        this.$store
+                            .dispatch('getUserInfo')
+                            .then(() => {
+                                this.globalData.initialize = true;
+                                console.log(this.globalData);
+                                if (this.globalData.initializeCallback) {
+                                    this.globalData.initializeCallback();
+                                }
+                            })
+                            .catch(() => {
+                                this.globalData.initialize = true;
+                            });
+                    })
+                    .catch(e => {
+                        console.log(e);
+                    });
+            }
+        });
+        // wx.getSystemInfo({
+        //   success: res => {
+        //     console.log(res);
+        //     this.$store.commit("setSystemInfo", res);
+        //   }
+        // });
 
-    // Do something initial when launch.
-  },
-  onShow(options) {
-    // Do something when show.
-    console.log("App onShow");
-  },
-  onHide() {
-    // Do something when hide.
-    console.log("App onHide");
-  },
-  onError(msg) {
-    console.log("App onError");
-    console.log(msg);
-  },
-  globalData() {
-    return {
-      a: "I am global data"
-    };
-  }
+        // Do something initial when launch.
+    },
+    onShow(options) {
+        // Do something when show.
+        console.log('App onShow');
+    },
+    onHide() {
+        // Do something when hide.
+        console.log('App onHide');
+    },
+    onError(msg) {
+        console.log('App onError');
+        console.log(msg);
+    },
+    globalData() {
+        return {
+            a: 'I am global data'
+        };
+    }
 };
 </script>
 
 <style lang="less" scoped>
 /deep/.van-image {
-  display: block;
+    display: block;
 }
 </style>

+ 1 - 1
src/components/add.vue

@@ -1,5 +1,5 @@
 <template>
-  <div>1111</div>
+    <div>1111</div>
 </template>
 <script>
 export default {};

+ 73 - 73
src/main.js

@@ -1,22 +1,22 @@
-import App from "./App";
-import Vue from "vue";
-import VHtmlPlugin from "@megalo/vhtml-plugin";
-import Vuex from "vuex";
-import http from "./plugins/http";
+import App from './App';
+import Vue from 'vue';
+import VHtmlPlugin from '@megalo/vhtml-plugin';
+import Vuex from 'vuex';
+import http from './plugins/http';
 // import Dialog from "./vant/dialog/dialog";
-import common from "./mixins/common";
-import "./styles/font.less";
-import "./styles/vanIndex.less";
+import common from './mixins/common';
+import './styles/font.less';
+import './styles/vanIndex.less';
 
 Vue.prototype.$colors = {
-  prim: "#FF7F1F",
-  red: "#F42202"
+    prim: '#FF7F1F',
+    red: '#F42202'
 };
 
 Vue.use(VHtmlPlugin);
 Vue.use(Vuex);
 
-const store = require("./store").default;
+const store = require('./store').default;
 Vue.prototype.$store = store;
 Vue.use(http);
 const app = new Vue(App);
@@ -24,70 +24,70 @@ Vue.mixin(common);
 app.$mount();
 
 export default {
-  config: {
-    // pages 的首个页面会被编译成首页
-    pages: ["pages/news", "pages/vuex/vuex", "pages/Home"],
-    tabBar: {
-      color: "#333",
-      selectedColor: "#007d37",
-      list: [
-        {
-          pagePath: "pages/Home",
-          text: "home",
-          iconPath: "native/tabbar/home.png",
-          selectedIconPath: "native/tabbar/home_on.png"
+    config: {
+        // pages 的首个页面会被编译成首页
+        pages: ['pages/news', 'pages/vuex/vuex', 'pages/Home'],
+        tabBar: {
+            color: '#333',
+            selectedColor: '#007d37',
+            list: [
+                {
+                    pagePath: 'pages/Home',
+                    text: 'home',
+                    iconPath: 'native/tabbar/home.png',
+                    selectedIconPath: 'native/tabbar/home_on.png'
+                },
+                {
+                    pagePath: 'pages/news',
+                    text: 'news',
+                    iconPath: 'native/tabbar/mine.png',
+                    selectedIconPath: 'native/tabbar/mine_on.png'
+                },
+                {
+                    pagePath: 'pages/vuex/vuex',
+                    text: 'vuex',
+                    iconPath: 'native/tabbar/vue.png',
+                    selectedIconPath: 'native/tabbar/vue_on.png'
+                }
+            ]
         },
-        {
-          pagePath: "pages/news",
-          text: "news",
-          iconPath: "native/tabbar/mine.png",
-          selectedIconPath: "native/tabbar/mine_on.png"
+        usingComponents: {
+            'van-image': '/vant/image/index',
+            'van-button': '/vant/button/index',
+            'van-tabs': '/vant/tabs/index',
+            'van-tab': '/vant/tab/index',
+            'van-notice-bar': '/vant/notice-bar/index',
+            'van-icon': '/vant/icon/index',
+            'van-grid-item ': '/vant/grid-item/index',
+            'van-count-down': '/vant/count-down/index',
+            'van-dialog': '/vant/dialog/index',
+            'van-search': '/vant/search/index',
+            'van-empty': '/vant/empty/index',
+            'van-sticky': '/vant/sticky/index',
+            'van-loading': '/vant/loading/index',
+            'van-action-sheet': '/vant/action-sheet/index',
+            'van-picker': '/vant/picker/index',
+            'van-cell-group': '/vant/cell-group/index',
+            'van-cell': '/vant/cell/index',
+            'van-field': '/vant/field/index',
+            'van-uploader': '/vant/uploader/index',
+            'van-checkbox': '/vant/checkbox/index',
+            'van-panel': '/vant/panel/index',
+            'van-overlay': '/vant/overlay/index',
+            'van-stepper': '/vant/stepper/index',
+            'van-steps': '/vant/steps/index',
+            'van-rate': '/vant/rate/index',
+            'van-popup': '/vant/popup/index',
+            'van-area': '/vant/area/index',
+            'van-goods-action': 'vant/goods-action/index',
+            'van-goods-action-icon': 'vant/goods-action-icon/index',
+            'van-goods-action-button': 'vant/goods-action-button/index',
+            'van-calendar': 'vant/calendar/index'
         },
-        {
-          pagePath: "pages/vuex/vuex",
-          text: "vuex",
-          iconPath: "native/tabbar/vue.png",
-          selectedIconPath: "native/tabbar/vue_on.png"
+        window: {
+            backgroundTextStyle: 'light',
+            navigationBarBackgroundColor: '#fff',
+            navigationBarTextStyle: 'black'
         }
-      ]
-    },
-    usingComponents: {
-      "van-image": "/vant/image/index",
-      "van-button": "/vant/button/index",
-      "van-tabs": "/vant/tabs/index",
-      "van-tab": "/vant/tab/index",
-      "van-notice-bar": "/vant/notice-bar/index",
-      "van-icon": "/vant/icon/index",
-      "van-grid-item ": "/vant/grid-item/index",
-      "van-count-down": "/vant/count-down/index",
-      "van-dialog": "/vant/dialog/index",
-      "van-search": "/vant/search/index",
-      "van-empty": "/vant/empty/index",
-      "van-sticky": "/vant/sticky/index",
-      "van-loading": "/vant/loading/index",
-      "van-action-sheet": "/vant/action-sheet/index",
-      "van-picker": "/vant/picker/index",
-      "van-cell-group": "/vant/cell-group/index",
-      "van-cell": "/vant/cell/index",
-      "van-field": "/vant/field/index",
-      "van-uploader": "/vant/uploader/index",
-      "van-checkbox": "/vant/checkbox/index",
-      "van-panel": "/vant/panel/index",
-      "van-overlay": "/vant/overlay/index",
-      "van-stepper": "/vant/stepper/index",
-      "van-steps": "/vant/steps/index",
-      "van-rate": "/vant/rate/index",
-      "van-popup": "/vant/popup/index",
-      "van-area": "/vant/area/index",
-      "van-goods-action": "vant/goods-action/index",
-      "van-goods-action-icon": "vant/goods-action-icon/index",
-      "van-goods-action-button": "vant/goods-action-button/index",
-      "van-calendar": "vant/calendar/index"
-    },
-    window: {
-      backgroundTextStyle: "light",
-      navigationBarBackgroundColor: "#fff",
-      navigationBarTextStyle: "black"
     }
-  }
 };

+ 55 - 55
src/mixins/allPage.js

@@ -1,59 +1,59 @@
 export default {
-  data() {
-    return {
-      caseStatusList: [
-        {
-          value: "CREATED",
-          label: "待支付"
-        },
-        {
-          value: "CANCELED",
-          label: "已取消"
-        },
-        {
-          value: "PAYED",
-          label: "待发货"
-        },
-        {
-          value: "SEND",
-          label: "待收货"
-        },
-        {
-          value: "TAKEN",
-          label: "已收货"
-        },
-        {
-          value: "REFUND",
-          label: "申请退款"
-        },
-        {
-          value: "REFUNDED",
-          label: "已退款"
-        },
-        {
-          value: "COMPETED",
-          label: "已完成"
-        },
-        {
-          value: "ALL",
-          label: "全部"
+    data() {
+        return {
+            caseStatusList: [
+                {
+                    value: 'CREATED',
+                    label: '待支付'
+                },
+                {
+                    value: 'CANCELED',
+                    label: '已取消'
+                },
+                {
+                    value: 'PAYED',
+                    label: '待发货'
+                },
+                {
+                    value: 'SEND',
+                    label: '待收货'
+                },
+                {
+                    value: 'TAKEN',
+                    label: '已收货'
+                },
+                {
+                    value: 'REFUND',
+                    label: '申请退款'
+                },
+                {
+                    value: 'REFUNDED',
+                    label: '已退款'
+                },
+                {
+                    value: 'COMPETED',
+                    label: '已完成'
+                },
+                {
+                    value: 'ALL',
+                    label: '全部'
+                }
+            ]
+        };
+    },
+    methods: {
+        allStatus(label) {
+            if (label) {
+                return (
+                    [...this.caseStatusList].find(item => {
+                        return item.label === label;
+                    }) || {
+                        value: ''
+                    }
+                ).value;
+            } else {
+                return '';
+            }
         }
-      ]
-    };
-  },
-  methods: {
-    allStatus(label) {
-      if (label) {
-        return (
-          [...this.caseStatusList].find(item => {
-            return item.label === label;
-          }) || {
-            value: ""
-          }
-        ).value;
-      } else {
-        return "";
-      }
     }
-  }
 };

+ 39 - 39
src/mixins/cardPage.js

@@ -1,43 +1,43 @@
 export default {
-  data() {
-    return {
-      caseStatusList: [
-        {
-          value: "UNDO",
-          label: "未审核"
-        },
-        {
-          value: "WAIT",
-          label: "待开始"
-        },
-        {
-          value: "PROGRESS",
-          label: "进行中"
-        },
-        {
-          value: "SOLDOUT",
-          label: "已完成"
-        },
-        {
-          value: "FINISH",
-          label: "已结束"
+    data() {
+        return {
+            caseStatusList: [
+                {
+                    value: 'UNDO',
+                    label: '未审核'
+                },
+                {
+                    value: 'WAIT',
+                    label: '待开始'
+                },
+                {
+                    value: 'PROGRESS',
+                    label: '进行中'
+                },
+                {
+                    value: 'SOLDOUT',
+                    label: '已完成'
+                },
+                {
+                    value: 'FINISH',
+                    label: '已结束'
+                }
+            ]
+        };
+    },
+    methods: {
+        getStatus(label) {
+            if (label) {
+                return (
+                    [...this.caseStatusList].find(item => {
+                        return item.label === label;
+                    }) || {
+                        value: ''
+                    }
+                ).value;
+            } else {
+                return '';
+            }
         }
-      ]
-    };
-  },
-  methods: {
-    getStatus(label) {
-      if (label) {
-        return (
-          [...this.caseStatusList].find(item => {
-            return item.label === label;
-          }) || {
-            value: ""
-          }
-        ).value;
-      } else {
-        return "";
-      }
     }
-  }
 };

+ 117 - 117
src/mixins/common.js

@@ -1,125 +1,125 @@
 export default {
-  onLoad() {
-    const app = getApp();
-    if (this.loginMethods) {
-      if (app.globalData.initialize) {
-        this.loginMethods();
-      } else {
-        app.globalData.initializeCallback = () => {
-          this.loginMethods();
-        };
-      }
-    }
-  },
-  computed: {
-    isLogin() {
-      return !!this.$store.state.userInfo;
-    }
-  },
-  methods: {
-    navigateTo(url, checkLogin = true) {
-      if (checkLogin) {
-        this.checkLogin().then(() => {
-          if (url) {
-            wx.navigateTo({
-              url: url
-            });
-          }
-        });
-      } else {
-        if (url) {
-          wx.navigateTo({
-            url: url
-          });
+    onLoad() {
+        const app = getApp();
+        if (this.loginMethods) {
+            if (app.globalData.initialize) {
+                this.loginMethods();
+            } else {
+                app.globalData.initializeCallback = () => {
+                    this.loginMethods();
+                };
+            }
         }
-      }
     },
-    checkLogin() {
-      if (!this.isLogin) {
-        wx.navigateTo({
-          url: "/pages/authorized"
-        });
-        return Promise.reject("未登录");
-      }
-      return Promise.resolve();
-    },
-    navigateBack(num = 1) {
-      wx.navigateBack({
-        delta: num
-      });
+    computed: {
+        isLogin() {
+            return !!this.$store.state.userInfo;
+        }
     },
-    preview(img, urls = []) {
-      if (!img) {
-        return;
-      }
-      if (urls.length === 0) {
-        urls = [img];
-      }
+    methods: {
+        navigateTo(url, checkLogin = true) {
+            if (checkLogin) {
+                this.checkLogin().then(() => {
+                    if (url) {
+                        wx.navigateTo({
+                            url: url
+                        });
+                    }
+                });
+            } else {
+                if (url) {
+                    wx.navigateTo({
+                        url: url
+                    });
+                }
+            }
+        },
+        checkLogin() {
+            if (!this.isLogin) {
+                wx.navigateTo({
+                    url: '/pages/authorized'
+                });
+                return Promise.reject('未登录');
+            }
+            return Promise.resolve();
+        },
+        navigateBack(num = 1) {
+            wx.navigateBack({
+                delta: num
+            });
+        },
+        preview(img, urls = []) {
+            if (!img) {
+                return;
+            }
+            if (urls.length === 0) {
+                urls = [img];
+            }
 
-      let current = urls.findIndex(item => {
-        return item === img;
-      });
+            let current = urls.findIndex(item => {
+                return item === img;
+            });
 
-      wx.previewImage({
-        current: current, // 当前显示图片的http链接
-        urls: urls // 需要预览的图片http链接列表
-      });
-    },
-    choosePhoto() {
-      return new Promise((resolve, reject) => {
-        wx.chooseImage({
-          count: 1, // 默认9
-          sizeType: ["original"], // 可以指定是原图还是压缩图,默认二者都有
-          sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
-          success: res => {
-            const src = res.tempFilePaths[0];
-            this.$http
-              .uploadFile(src)
-              .then(res => {
-                resolve(res);
-              })
-              .catch(e => {
-                reject(e);
-              });
-          }
-        });
-      });
-    },
-    phoneCall(phone = "18366668888") {
-      wx.makePhoneCall({
-        phoneNumber: phone
-      });
-    },
-    goHome() {
-      wx.switchTab({
-        url: "/pages/Home"
-      });
-    },
-    getNumStr(num) {
-      if (num < 10) {
-        return "0" + num;
-      } else {
-        return num;
-      }
-    },
-    toast(title, icon = "none", duration = 1500) {
-      wx.showToast({
-        icon: icon,
-        title: title,
-        mask: true,
-        duration: duration
-      });
-    },
-    showLoading() {
-      wx.showLoading({
-        title: "加载中..."
-      });
-    },
-    hideLoading() {
-      wx.hideLoading();
-    },
-    wait() {
-      this.toast("敬请期待");
+            wx.previewImage({
+                current: current, // 当前显示图片的http链接
+                urls: urls // 需要预览的图片http链接列表
+            });
+        },
+        choosePhoto() {
+            return new Promise((resolve, reject) => {
+                wx.chooseImage({
+                    count: 1, // 默认9
+                    sizeType: ['original'], // 可以指定是原图还是压缩图,默认二者都有
+                    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
+                    success: res => {
+                        const src = res.tempFilePaths[0];
+                        this.$http
+                            .uploadFile(src)
+                            .then(res => {
+                                resolve(res);
+                            })
+                            .catch(e => {
+                                reject(e);
+                            });
+                    }
+                });
+            });
+        },
+        phoneCall(phone = '18366668888') {
+            wx.makePhoneCall({
+                phoneNumber: phone
+            });
+        },
+        goHome() {
+            wx.switchTab({
+                url: '/pages/Home'
+            });
+        },
+        getNumStr(num) {
+            if (num < 10) {
+                return '0' + num;
+            } else {
+                return num;
+            }
+        },
+        toast(title, icon = 'none', duration = 1500) {
+            wx.showToast({
+                icon: icon,
+                title: title,
+                mask: true,
+                duration: duration
+            });
+        },
+        showLoading() {
+            wx.showLoading({
+                title: '加载中...'
+            });
+        },
+        hideLoading() {
+            wx.hideLoading();
+        },
+        wait() {
+            this.toast('敬请期待');
+        }
     }
-  }
 };

+ 0 - 165
src/mixins/plugins/http.js

@@ -1,165 +0,0 @@
-const baseUrl = process.env.VUE_APP_BASE_URL;
-function parseUrl(url) {
-    let _baseUrl = baseUrl;
-    if (url.startsWith('http')) {
-        return url;
-    }
-    if (!_baseUrl.endsWith('/')) {
-        _baseUrl += '/';
-    }
-    if (url.startsWith('/')) {
-        url = url.slice(1);
-    }
-    return _baseUrl + url;
-}
-const http = {
-    parseUrl: parseUrl,
-    setToken(token) {
-        wx.setStorageSync('token', token);
-        this.token = token;
-    },
-    clearToken() {
-        this.token = '';
-        wx.removeStorageSync('token');
-        console.log('clear token');
-    },
-    getToken() {
-        if (!this.token) {
-            try {
-                this.token = wx.getStorageSync('token');
-            } catch (e) {}
-        }
-        return this.token;
-    },
-    get(url, params, options) {
-        options = options || {};
-        return new Promise((resolve, reject) => {
-            wx.request({
-                method: 'GET',
-                url: parseUrl(url),
-                data: params,
-                dataType: 'json',
-                header: {
-                    Accept: 'application/json',
-                    Authorization: this.getToken() ? 'Bearer ' + this.getToken() : 'Bearer ',
-                    ...(options.header || {})
-                },
-                success(res) {
-                    if (res && res.statusCode === 200) {
-                        resolve(res.data);
-                    } else {
-                        reject(res.data || res);
-                    }
-                },
-                fail(err) {
-                    reject(err.data || err);
-                }
-            });
-        });
-    },
-    post(url, data, options, backHeader = false) {
-        console.log('post');
-        options = options || {};
-        return new Promise((resolve, reject) => {
-            wx.request({
-                method: 'post',
-                url: parseUrl(url),
-                data: data,
-                dataType: 'json',
-                header: {
-                    Accept: 'application/json',
-                    'content-type': 'application/x-www-form-urlencoded',
-                    Authorization: this.getToken() ? 'Bearer ' + this.getToken() : '',
-                    ...(options.header || {})
-                },
-                success(res) {
-                    if (res && res.statusCode === 200) {
-                        resolve(backHeader ? res : res.data);
-                    } else {
-                        reject(res.data || res);
-                    }
-                },
-                fail(err) {
-                    reject(err.data || err);
-                }
-            });
-        });
-    },
-    postJson(url, data, options, backHeader = false) {
-        options = options || {};
-        return new Promise((resolve, reject) => {
-            wx.request({
-                method: 'post',
-                url: parseUrl(url),
-                data: data,
-                dataType: 'json',
-                header: {
-                    Accept: 'application/json',
-                    'Content-Type': 'application/json',
-                    Authorization: this.getToken() ? 'Bearer ' + this.getToken() : '',
-                    ...(options.header || {})
-                },
-                success(res) {
-                    if (res && res.statusCode === 200) {
-                        resolve(backHeader ? res : res.data);
-                    } else {
-                        reject(res.data || res);
-                    }
-                },
-                fail(err) {
-                    reject(err.data || err);
-                }
-            });
-        });
-    },
-    uploadFile(filePath, options) {
-        options = options || {};
-        return new Promise((resolve, reject) => {
-            wx.uploadFile({
-                url: baseUrl + '/upload/file',
-                filePath: filePath,
-                name: 'file',
-                header: {
-                    Accept: 'application/json',
-                    'content-type': 'application/x-www-form-urlencoded',
-                    Authorization: this.getToken() ? 'Bearer ' + this.getToken() : '',
-                    ...(options.header || {})
-                },
-                formData: options.formData || {},
-                success(res) {
-                    if (res && res.statusCode === 200) {
-                        try {
-                            resolve(res.data);
-                        } catch (e) {
-                            reject(e);
-                        }
-                    } else {
-                        reject(res);
-                    }
-                },
-                fail(err) {
-                    reject(err);
-                }
-            });
-        });
-    }
-};
-export default {
-    http: http,
-    install(_Vue) {
-        _Vue.prototype.$baseUrl = baseUrl;
-        _Vue.prototype.$http = http;
-        _Vue.prototype.$request = options => {
-            options = options || {};
-            options.url = parseUrl(options.url);
-            return new Promise((resolve, reject) => {
-                options.success = res => {
-                    resolve(res);
-                };
-                options.success = err => {
-                    reject(err);
-                };
-            });
-        };
-    }
-};

+ 22 - 22
src/mixins/store.js

@@ -1,26 +1,26 @@
 export default {
-  data() {
-    return {
-      storeInfo: {}
-    };
-  },
-  computed: {
-    city() {
-      if (this.storeInfo) {
-        if (/[\u4e00-\u9fa5]/.test(this.storeInfo.city)) {
-          let province = this.storeInfo.province.replace(/省/, "");
-          province = province.replace(/自治区/, "");
-          let city = this.storeInfo.city.replace(/市/, "");
-          return province + " " + city;
-        }
-      }
-
-      return "";
+    data() {
+        return {
+            storeInfo: {}
+        };
     },
-    storeLogo() {
-      return this.storeInfo.logo
-        ? this.storeInfo.logo + "?x-oss-process=image/circle,r_300/format,png"
-        : "/native/imgs/defaultLogo.png";
+    computed: {
+        city() {
+            if (this.storeInfo) {
+                if (/[\u4e00-\u9fa5]/.test(this.storeInfo.city)) {
+                    let province = this.storeInfo.province.replace(/省/, '');
+                    province = province.replace(/自治区/, '');
+                    let city = this.storeInfo.city.replace(/市/, '');
+                    return province + ' ' + city;
+                }
+            }
+
+            return '';
+        },
+        storeLogo() {
+            return this.storeInfo.logo
+                ? this.storeInfo.logo + '?x-oss-process=image/circle,r_300/format,png'
+                : '/native/imgs/defaultLogo.png';
+        }
     }
-  }
 };

+ 8 - 13
src/pages/Home.vue

@@ -5,25 +5,20 @@
 }
 </config>
 <template>
-  <div class="con">
-    <van-button type="primary">朴素按钮</van-button>
-    <van-image
-      width="10rem"
-      height="10rem"
-      fit="contain"
-      src="https://img.yzcdn.cn/vant/cat.jpeg"
-    />
-    <add></add>
-  </div>
+    <div class="con">
+        <van-button type="primary">朴素按钮</van-button>
+        <van-image width="10rem" height="10rem" fit="contain" src="https://img.yzcdn.cn/vant/cat.jpeg" />
+        <add></add>
+    </div>
 </template>
 <script>
-import add from "../components/add.vue";
+import add from '../components/add.vue';
 export default {
-  components: { add }
+    components: { add }
 };
 </script>
 <style lang="less">
 .con {
-  background: @success;
+    background: @success;
 }
 </style>

+ 1 - 1
src/pages/news.vue

@@ -1,5 +1,5 @@
 <template>
-  <div></div>
+    <div></div>
 </template>
 <script>
 export default {};

+ 22 - 27
src/pages/vuex/vuex.vue

@@ -8,38 +8,33 @@
 </config>
 
 <template>
-  <div id="app">
-    Clicked: {{ $store.state.counter.count }} times, count is {{ evenOrOdd }}.
-    <button @click="increment() | test()">+</button>
-    <button @click="decrement">-</button>
-    <button @click="incrementIfOdd">Increment if odd</button>
-    <button @click="incrementAsync">Increment async</button>
-    globalData:{{ globalData }}
-  </div>
+    <div id="app">
+        Clicked: {{ $store.state.counter.count }} times, count is {{ evenOrOdd }}.
+        <button @click="increment() | test()">+</button>
+        <button @click="decrement">-</button>
+        <button @click="incrementIfOdd">Increment if odd</button>
+        <button @click="incrementAsync">Increment async</button>
+        globalData:{{ globalData }}
+    </div>
 </template>
 
 <script>
-import { mapGetters, mapActions } from "vuex";
+import { mapGetters, mapActions } from 'vuex';
 
 export default {
-  computed: mapGetters(["evenOrOdd"]),
-  data() {
-    return {};
-  },
-  methods: {
-    ...mapActions([
-      "increment",
-      "decrement",
-      "incrementIfOdd",
-      "incrementAsync"
-    ]),
-    test: function() {
-      this.globalData["a"]++;
+    computed: mapGetters(['evenOrOdd']),
+    data() {
+        return {};
+    },
+    methods: {
+        ...mapActions(['increment', 'decrement', 'incrementIfOdd', 'incrementAsync']),
+        test: function() {
+            this.globalData['a']++;
+        }
+    },
+    created() {
+        var appInstance = getApp();
+        this.globalData = appInstance.globalData;
     }
-  },
-  created() {
-    var appInstance = getApp();
-    this.globalData = appInstance.globalData;
-  }
 };
 </script>

+ 155 - 157
src/plugins/http.js

@@ -1,167 +1,165 @@
 const baseUrl = process.env.VUE_APP_BASE_URL;
 function parseUrl(url) {
-  let _baseUrl = baseUrl;
-  if (url.startsWith("http")) {
-    return url;
-  }
-  if (!_baseUrl.endsWith("/")) {
-    _baseUrl += "/";
-  }
-  if (url.startsWith("/")) {
-    url = url.slice(1);
-  }
-  return _baseUrl + url;
+    let _baseUrl = baseUrl;
+    if (url.startsWith('http')) {
+        return url;
+    }
+    if (!_baseUrl.endsWith('/')) {
+        _baseUrl += '/';
+    }
+    if (url.startsWith('/')) {
+        url = url.slice(1);
+    }
+    return _baseUrl + url;
 }
 const http = {
-  parseUrl: parseUrl,
-  setToken(token) {
-    wx.setStorageSync("token", token);
-    this.token = token;
-  },
-  clearToken() {
-    this.token = "";
-    wx.removeStorageSync("token");
-    console.log("clear token");
-  },
-  getToken() {
-    if (!this.token) {
-      try {
-        this.token = wx.getStorageSync("token");
-      } catch (e) {}
-    }
-    return this.token;
-  },
-  get(url, params, options) {
-    options = options || {};
-    return new Promise((resolve, reject) => {
-      wx.request({
-        method: "GET",
-        url: parseUrl(url),
-        data: params,
-        dataType: "json",
-        header: {
-          Accept: "application/json",
-          Authorization: this.getToken()
-            ? "Bearer " + this.getToken()
-            : "Bearer ",
-          ...(options.header || {})
-        },
-        success(res) {
-          if (res && res.statusCode === 200) {
-            resolve(res.data);
-          } else {
-            reject(res.data || res);
-          }
-        },
-        fail(err) {
-          reject(err.data || err);
-        }
-      });
-    });
-  },
-  post(url, data, options, backHeader = false) {
-    console.log("post");
-    options = options || {};
-    return new Promise((resolve, reject) => {
-      wx.request({
-        method: "post",
-        url: parseUrl(url),
-        data: data,
-        dataType: "json",
-        header: {
-          Accept: "application/json",
-          "content-type": "application/x-www-form-urlencoded",
-          Authorization: this.getToken() ? "Bearer " + this.getToken() : "",
-          ...(options.header || {})
-        },
-        success(res) {
-          if (res && res.statusCode === 200) {
-            resolve(backHeader ? res : res.data);
-          } else {
-            reject(res.data || res);
-          }
-        },
-        fail(err) {
-          reject(err.data || err);
-        }
-      });
-    });
-  },
-  postJson(url, data, options, backHeader = false) {
-    options = options || {};
-    return new Promise((resolve, reject) => {
-      wx.request({
-        method: "post",
-        url: parseUrl(url),
-        data: data,
-        dataType: "json",
-        header: {
-          Accept: "application/json",
-          "Content-Type": "application/json",
-          Authorization: this.getToken() ? "Bearer " + this.getToken() : "",
-          ...(options.header || {})
-        },
-        success(res) {
-          if (res && res.statusCode === 200) {
-            resolve(backHeader ? res : res.data);
-          } else {
-            reject(res.data || res);
-          }
-        },
-        fail(err) {
-          reject(err.data || err);
-        }
-      });
-    });
-  },
-  uploadFile(filePath, options) {
-    options = options || {};
-    return new Promise((resolve, reject) => {
-      wx.uploadFile({
-        url: baseUrl + "/upload/file",
-        filePath: filePath,
-        name: "file",
-        header: {
-          Accept: "application/json",
-          "content-type": "application/x-www-form-urlencoded",
-          Authorization: this.getToken() ? "Bearer " + this.getToken() : "",
-          ...(options.header || {})
-        },
-        formData: options.formData || {},
-        success(res) {
-          if (res && res.statusCode === 200) {
+    parseUrl: parseUrl,
+    setToken(token) {
+        wx.setStorageSync('token', token);
+        this.token = token;
+    },
+    clearToken() {
+        this.token = '';
+        wx.removeStorageSync('token');
+        console.log('clear token');
+    },
+    getToken() {
+        if (!this.token) {
             try {
-              resolve(res.data);
-            } catch (e) {
-              reject(e);
-            }
-          } else {
-            reject(res);
-          }
-        },
-        fail(err) {
-          reject(err);
+                this.token = wx.getStorageSync('token');
+            } catch (e) {}
         }
-      });
-    });
-  }
+        return this.token;
+    },
+    get(url, params, options) {
+        options = options || {};
+        return new Promise((resolve, reject) => {
+            wx.request({
+                method: 'GET',
+                url: parseUrl(url),
+                data: params,
+                dataType: 'json',
+                header: {
+                    Accept: 'application/json',
+                    Authorization: this.getToken() ? 'Bearer ' + this.getToken() : 'Bearer ',
+                    ...(options.header || {})
+                },
+                success(res) {
+                    if (res && res.statusCode === 200) {
+                        resolve(res.data);
+                    } else {
+                        reject(res.data || res);
+                    }
+                },
+                fail(err) {
+                    reject(err.data || err);
+                }
+            });
+        });
+    },
+    post(url, data, options, backHeader = false) {
+        console.log('post');
+        options = options || {};
+        return new Promise((resolve, reject) => {
+            wx.request({
+                method: 'post',
+                url: parseUrl(url),
+                data: data,
+                dataType: 'json',
+                header: {
+                    Accept: 'application/json',
+                    'content-type': 'application/x-www-form-urlencoded',
+                    Authorization: this.getToken() ? 'Bearer ' + this.getToken() : '',
+                    ...(options.header || {})
+                },
+                success(res) {
+                    if (res && res.statusCode === 200) {
+                        resolve(backHeader ? res : res.data);
+                    } else {
+                        reject(res.data || res);
+                    }
+                },
+                fail(err) {
+                    reject(err.data || err);
+                }
+            });
+        });
+    },
+    postJson(url, data, options, backHeader = false) {
+        options = options || {};
+        return new Promise((resolve, reject) => {
+            wx.request({
+                method: 'post',
+                url: parseUrl(url),
+                data: data,
+                dataType: 'json',
+                header: {
+                    Accept: 'application/json',
+                    'Content-Type': 'application/json',
+                    Authorization: this.getToken() ? 'Bearer ' + this.getToken() : '',
+                    ...(options.header || {})
+                },
+                success(res) {
+                    if (res && res.statusCode === 200) {
+                        resolve(backHeader ? res : res.data);
+                    } else {
+                        reject(res.data || res);
+                    }
+                },
+                fail(err) {
+                    reject(err.data || err);
+                }
+            });
+        });
+    },
+    uploadFile(filePath, options) {
+        options = options || {};
+        return new Promise((resolve, reject) => {
+            wx.uploadFile({
+                url: baseUrl + '/upload/file',
+                filePath: filePath,
+                name: 'file',
+                header: {
+                    Accept: 'application/json',
+                    'content-type': 'application/x-www-form-urlencoded',
+                    Authorization: this.getToken() ? 'Bearer ' + this.getToken() : '',
+                    ...(options.header || {})
+                },
+                formData: options.formData || {},
+                success(res) {
+                    if (res && res.statusCode === 200) {
+                        try {
+                            resolve(res.data);
+                        } catch (e) {
+                            reject(e);
+                        }
+                    } else {
+                        reject(res);
+                    }
+                },
+                fail(err) {
+                    reject(err);
+                }
+            });
+        });
+    }
 };
 export default {
-  http: http,
-  install(_Vue) {
-    _Vue.prototype.$baseUrl = baseUrl;
-    _Vue.prototype.$http = http;
-    _Vue.prototype.$request = options => {
-      options = options || {};
-      options.url = parseUrl(options.url);
-      return new Promise((resolve, reject) => {
-        options.success = res => {
-          resolve(res);
+    http: http,
+    install(_Vue) {
+        _Vue.prototype.$baseUrl = baseUrl;
+        _Vue.prototype.$http = http;
+        _Vue.prototype.$request = options => {
+            options = options || {};
+            options.url = parseUrl(options.url);
+            return new Promise((resolve, reject) => {
+                options.success = res => {
+                    resolve(res);
+                };
+                options.success = err => {
+                    reject(err);
+                };
+            });
         };
-        options.success = err => {
-          reject(err);
-        };
-      });
-    };
-  }
+    }
 };

+ 54 - 54
src/store/index.js

@@ -1,60 +1,60 @@
-import Vuex from "vuex";
-import http from "../plugins/http";
+import Vuex from 'vuex';
+import http from '../plugins/http';
 export default new Vuex.Store({
-  state: {
-    sessionKey: "",
-    safeArea: {
-      top: 0,
-      botton: 0
+    state: {
+        sessionKey: '',
+        safeArea: {
+            top: 0,
+            botton: 0
+        },
+        systemInfo: {
+            statusBarHeight: 44
+        },
+        userInfo: null,
+        userStoreInfo: null
     },
-    systemInfo: {
-      statusBarHeight: 44
-    },
-    userInfo: null,
-    userStoreInfo: null
-  },
-  mutations: {
-    setUserInfo(state, userInfo) {
-      state.userInfo = userInfo;
-    },
-    setSessionKey(state, sessionKey) {
-      state.sessionKey = sessionKey;
-    },
-    setSystemInfo(state, systemInfo) {
-      state.systemInfo = systemInfo;
-    },
-    setUserStoreInfo(state, userStoreInfo) {
-      state.userStoreInfo = userStoreInfo;
-    }
-  },
-  actions: {
-    getUserInfo(context) {
-      return http.http.get("/user/my").then(res => {
-        if (res.sex || res.nickname.indexOf("用户") === -1) {
-          context.commit("setUserInfo", res);
-        } else {
-          context.commit("setUserInfo", null);
+    mutations: {
+        setUserInfo(state, userInfo) {
+            state.userInfo = userInfo;
+        },
+        setSessionKey(state, sessionKey) {
+            state.sessionKey = sessionKey;
+        },
+        setSystemInfo(state, systemInfo) {
+            state.systemInfo = systemInfo;
+        },
+        setUserStoreInfo(state, userStoreInfo) {
+            state.userStoreInfo = userStoreInfo;
         }
+    },
+    actions: {
+        getUserInfo(context) {
+            return http.http.get('/user/my').then(res => {
+                if (res.sex || res.nickname.indexOf('用户') === -1) {
+                    context.commit('setUserInfo', res);
+                } else {
+                    context.commit('setUserInfo', null);
+                }
 
-        return Promise.resolve(res);
-      });
+                return Promise.resolve(res);
+            });
+        }
+        // getUserStore(context) {
+        //   return http.http
+        //     .postJson("/store/all", {
+        //       query: {
+        //         userId: context.state.userInfo.id
+        //       }
+        //     })
+        //     .then(res => {
+        //       if (res.empty) {
+        //         context.commit("setUserStoreInfo", null);
+        //         return Promise.reject();
+        //       } else {
+        //         context.commit("setUserStoreInfo", res.content[0]);
+        //         return Promise.resolve(res.content[0]);
+        //       }
+        //     });
+        // }
     }
-    // getUserStore(context) {
-    //   return http.http
-    //     .postJson("/store/all", {
-    //       query: {
-    //         userId: context.state.userInfo.id
-    //       }
-    //     })
-    //     .then(res => {
-    //       if (res.empty) {
-    //         context.commit("setUserStoreInfo", null);
-    //         return Promise.reject();
-    //       } else {
-    //         context.commit("setUserStoreInfo", res.content[0]);
-    //         return Promise.resolve(res.content[0]);
-    //       }
-    //     });
-    // }
-  }
 });