yuantianjiao hace 6 años
padre
commit
5e953e0a35
Se han modificado 7 ficheros con 92 adiciones y 36 borrados
  1. 36
    10
      src/pages/user/App.vue
  2. 10
    4
      src/store/userCenter/userCenter.js
  3. 2
    0
      src/util/ajax.js
  4. 1
    1
      src/util/api.js
  5. 35
    15
      src/util/util.js
  6. 2
    3
      title.js
  7. 6
    3
      vue.config.js

+ 36
- 10
src/pages/user/App.vue Ver fichero

@@ -5,18 +5,44 @@
5 5
 </template>
6 6
 
7 7
 <script>
8
-  import '../../common/css/reset.css'
9
-
10
-  export default {
11
-    name: 'app',
12
-    components: {}
8
+import '../../common/css/reset.css'
9
+import { mapState, createNamespacedHelpers } from 'vuex'
10
+const { mapActions: actions } = createNamespacedHelpers('userCenter')
11
+export default {
12
+  name: 'app',
13
+  components: {},
14
+  computed: {
15
+    ...mapState({
16
+      userInfo: x => x.userCenter.userInfo,
17
+      org: x => x.app.orgId
18
+    })
19
+  },
20
+  created () {
21
+    if (location.search && this.toolClass.UrlSearch(location.search).code) {
22
+      this.code = this.toolClass.UrlSearch(location.search).code
23
+    } else {
24
+      this.code = null
25
+    }
26
+    this.getUserInfo({ org: this.org, code: this.code }).then((res) => {
27
+      if (typeof (res) === 'string') {
28
+        if (res.indexOf('401-') > -1) {
29
+          this.toolClass.getCode(res.substring(4, res.length))
30
+        }
31
+      }
32
+    }).catch((err) => {
33
+      console.log(err)
34
+    })
35
+  },
36
+  methods: {
37
+    ...actions(['getUserInfo'])
13 38
   }
39
+}
14 40
 </script>
15 41
 
16 42
 <style>
17
-  #app {
18
-    width: 100%;
19
-    height: 100%;
20
-    position: relative;
21
-  }
43
+#app {
44
+  width: 100%;
45
+  height: 100%;
46
+  position: relative;
47
+}
22 48
 </style>

+ 10
- 4
src/store/userCenter/userCenter.js Ver fichero

@@ -4,12 +4,18 @@ const http = new Object
4 4
 
5 5
 // 请求数据
6 6
 http.getUserInfo = (data) => { // 获取用户信息
7
+  let queryData
8
+  if (!data.code) {
9
+    queryData = {
10
+      org: data.org
11
+    }
12
+  } else {
13
+    queryData = data
14
+  }
7 15
   return new Promise((resolve, reject) => {
8 16
     Ajax(api.user.info.url, {
9 17
       method: api.user.info.method,
10
-      queryData: {
11
-        org: data.org
12
-      }
18
+      queryData: queryData
13 19
     }).then(res => {
14 20
       resolve(res)
15 21
     }).catch((err) => {
@@ -101,7 +107,7 @@ export default {
101 107
         })
102 108
       })
103 109
     },
104
-    submitData(context, data) {
110
+    submitData (context, data) {
105 111
       return new Promise((resolve) => {
106 112
         http.submitData(data).then((res) => {
107 113
           resolve(res)

+ 2
- 0
src/util/ajax.js Ver fichero

@@ -1,5 +1,6 @@
1 1
 import axios from 'axios'
2 2
 import qs from 'qs'
3
+import toolClass from './util'
3 4
 
4 5
 const Axios = axios.create({
5 6
   timeout: 60000,
@@ -52,6 +53,7 @@ const ajax = (...args) => {
52 53
         resolve(result)
53 54
       } else if (code === 401) {
54 55
         // reject(code)
56
+        toolClass.getCode()
55 57
       } else {
56 58
         Message({
57 59
           message: message,

+ 1
- 1
src/util/api.js Ver fichero

@@ -1,4 +1,4 @@
1
-const baseUrl = '/api'
1
+const baseUrl = '/api-v2'
2 2
 const wechat = '/wechat/:org'
3 3
 const guest = '/guest/:org'
4 4
 const common = '/common/:org'

+ 35
- 15
src/util/util.js Ver fichero

@@ -1,24 +1,44 @@
1 1
 const toolClass = {
2
-  dateFormat: (timestamp) => {
2
+  dateFormat: (timestamp, fmt) => {
3
+    if (!fmt) {
4
+      fmt = 'yyyy-MM-dd hh:mm'
5
+    }
6
+
3 7
     let date = new Date(timestamp)
4
-    let y = date.getFullYear()
5
-    let m = date.getMonth() + 1
6
-    let d = date.getDate()
7
-    let h = date.getHours()
8
-    let min = date.getMinutes()
9
-    if (m < 10) {
10
-      m = '0' + m
8
+    var o = {
9
+      'M+': date.getMonth() + 1,
10
+      'd+': date.getDate(),
11
+      'h+': date.getHours(),
12
+      'm+': date.getMinutes(),
13
+      's+': date.getSeconds(),
14
+      'q+': Math.floor((date.getMonth() + 3) / 3),
15
+      'S': date.getMilliseconds()
11 16
     }
12
-    if (d < 10) {
13
-      d = '0' + d
17
+    if (/(y+)/.test(fmt)) {
18
+      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
14 19
     }
15
-    if (h < 10) {
16
-      h = '0' + h
20
+    for (var k in o) {
21
+      if (new RegExp('(' + k + ')').test(fmt)) {
22
+        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
23
+      }
17 24
     }
18
-    if (min < 10) {
19
-      min = '0' + min
25
+    return fmt
26
+  },
27
+  UrlSearch: (urls) => {
28
+    let url = urls // 获取url中"?"符后的字串
29
+    let theRequest = {}
30
+    if (url.indexOf('?') !== -1) {
31
+      let str = url.substr(1)
32
+      let strs = str.split('&')
33
+      for (var i = 0; i < strs.length; i++) {
34
+        theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1])
35
+      }
20 36
     }
21
-    return y + '-' + m + '-' + d + ' ' + h + ':' + min
37
+    return theRequest
38
+  },
39
+  getCode: (appid) => {
40
+    let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${wechatConfig.redirect_uri}&response_type=${wechatConfig.response_type}&scope=${wechatConfig.scope}&state=${wechatConfig.state}#wechat_redirect`
41
+    window.location.href = url
22 42
   }
23 43
 }
24 44
 

+ 2
- 3
title.js Ver fichero

@@ -1,5 +1,4 @@
1 1
 module.exports = {
2
-  index: '主页',
3
-  'user/login': '登录',
4
-  'customer/home': '用户首页'
2
+  user: '城的空间',
3
+  sales: '城的空间案场端'
5 4
 }

+ 6
- 3
vue.config.js Ver fichero

@@ -15,14 +15,17 @@ glob.sync('./src/pages/**/app.js').forEach(path => {
15 15
 })
16 16
 module.exports = {
17 17
   pages,
18
+  baseUrl: './',
19
+  // 生产环境是否生成 sourceMap 文件
20
+  productionSourceMap: true,
18 21
   chainWebpack: config => config.plugins.delete('named-chunks'),
19 22
   devServer: {
20 23
     proxy: {
21
-      '/api': {
24
+      '/api-v2': {
22 25
         // target: 'https://dp.huiju360.com.cn/hj_operations',
23 26
         // target: 'http://192.168.0.62:8080', //wf
24
-        target: 'http://192.168.0.11:8080', //ys
25
-        // target: 'http://dev.ycjcjy.com', //zys
27
+        // target: 'http://192.168.0.11:8080', //ys
28
+        target: 'http://dev.ycjcjy.com', //frp
26 29
         changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
27 30
         // pathRewrite: {
28 31
         //   '^/api': '/api-v2/api'