xcx 4 лет назад
Родитель
Сommit
b0bf2d75f2

+ 4
- 3
package.json Просмотреть файл

@@ -35,12 +35,13 @@
35 35
   "license": "MIT",
36 36
   "dependencies": {
37 37
     "@babel/runtime": "^7.7.7",
38
+    "@tarojs/components": "3.0.7",
38 39
     "@tarojs/runtime": "3.0.7",
39 40
     "@tarojs/taro": "3.0.7",
40
-    "@tarojs/components": "3.0.7",
41
-    "vuex": "^3.0.0",
41
+    "qs": "^6.9.4",
42
+    "vue": "^2.5.0",
42 43
     "vue-template-compiler": "^2.5.0",
43
-    "vue": "^2.5.0"
44
+    "vuex": "^3.5.1"
44 45
   },
45 46
   "devDependencies": {
46 47
     "@types/webpack-env": "^1.13.6",

+ 5
- 1
src/app.js Просмотреть файл

@@ -1,10 +1,14 @@
1 1
 import Vue from 'vue'
2
-import store from './store'
2
+import store from './store/index'
3 3
 
4 4
 import './app.scss'
5 5
 
6 6
 // Vue.config.productionTip = false
7 7
 
8
+// 引入项目通用(顶层)方法对象
9
+import ToolClass from './util/PublicMethod/index'
10
+Vue.prototype.ToolClass = ToolClass
11
+
8 12
 const App = new Vue({
9 13
   store,
10 14
   onShow (options) {

+ 31
- 2
src/pages/HuiShengHuo/index.vue Просмотреть файл

@@ -2,11 +2,14 @@
2 2
   <view class="page">
3 3
     荟生活
4 4
     <view @tap="LinkTo">button</view>
5
+    <button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button>
5 6
   </view>
6 7
 </template>
7 8
 
8 9
 <script>
9 10
 
11
+import { createNamespacedHelpers } from 'vuex'
12
+const { mapState: mapUserState, mapActions: mapUserActions } = createNamespacedHelpers('user')
10 13
 export default {
11 14
   name: 'HuiShengHuo',
12 15
   data () {
@@ -14,16 +17,42 @@ export default {
14 17
 
15 18
     }
16 19
   },
20
+  computed: {
21
+    ...mapUserState({
22
+      UserPlaylist: x => x.UserPlaylist
23
+    })
24
+  },
17 25
   components: {
18 26
   },
19 27
   created () {
20 28
     this.Init()
21 29
   },
22 30
   methods: {
31
+    ...mapUserActions([
32
+      'GetUserPlaylist'
33
+    ]),
23 34
     Init () {
35
+      wx.getSetting({
36
+        success (res) {
37
+          if (res.authSetting['scope.userInfo']) {
38
+            // 已经授权,可以直接调用 getUserInfo 获取头像昵称
39
+            wx.getUserInfo({
40
+              success: function (res) {
41
+                window.alert(JSON.stringify(res.userInfo))
42
+              }
43
+            })
44
+          }
45
+        }
46
+      })
47
+      // this.GetUserPlaylist({ queryData: { accountId: 5, pageNum: 1, pageSize: 1000 } }).then((res) => {
48
+      //   console.log(this.UserPlaylist)
49
+      // })
50
+    },
51
+    LinkTo () {
52
+      wx.navigateTo({ url: 'ActivityList/index' })
24 53
     },
25
-    LinkTo(){
26
-      wx.navigateTo({url: 'ActivityList/index'})
54
+    bindGetUserInfo (e) {
55
+      console.log(e.detail.userInfo)
27 56
     }
28 57
   }
29 58
 }

+ 0
- 1
src/pages/SignIn/index.vue Просмотреть файл

@@ -5,7 +5,6 @@
5 5
 </template>
6 6
 
7 7
 <script>
8
-
9 8
 export default {
10 9
   name: 'SignIn',
11 10
   data () {

+ 22
- 0
src/store/index.js Просмотреть файл

@@ -0,0 +1,22 @@
1
+import Vue from 'vue'
2
+import Vuex from 'vuex'
3
+Vue.use(Vuex)
4
+
5
+const store = new Vuex.Store({
6
+  state: {
7
+  },
8
+  mutations: {
9
+  }
10
+})
11
+
12
+export const modules = {
13
+  user: () => require('./user/index').default
14
+}
15
+
16
+Object.keys(modules).forEach(modKey => {
17
+  const modNS = modKey.split('/')
18
+  const getMod = modules[modKey]
19
+  store.registerModule(...modNS, getMod())
20
+})
21
+
22
+export default store

+ 33
- 0
src/store/user/index.js Просмотреть файл

@@ -0,0 +1,33 @@
1
+
2
+import Api from '../../util/Api/index'
3
+import ToolClass from '../../util/PublicMethod/index'
4
+
5
+export default {
6
+  namespaced: true,
7
+  state: {
8
+    UserPlaylist: [] // 用户片单
9
+  },
10
+  mutations: {
11
+    UpdateUserPlaylist (state, data) {
12
+      state.UserPlaylist = data || []
13
+    }
14
+  },
15
+  actions: {
16
+    GetUserPlaylist (context, payload) {
17
+      return new Promise((resolve, reject) => {
18
+        ToolClass.WxRequest({
19
+          url: Api.GetUserPlaylist.url,
20
+          method: Api.GetUserPlaylist.method,
21
+          ...payload,
22
+          success (res) {
23
+            context.commit('UpdateUserPlaylist', res.data.data.list)
24
+            resolve(res)
25
+          },
26
+          error (res) {
27
+            reject(res)
28
+          }
29
+        })
30
+      })
31
+    }
32
+  }
33
+}

+ 11
- 0
src/util/Api/index.js Просмотреть файл

@@ -0,0 +1,11 @@
1
+
2
+const prefix = process.env.NODE_ENV === 'production' ? '' : ''
3
+
4
+const Api = {
5
+  GetUserPlaylist: { // 获取用户片单
6
+    method: 'get',
7
+    url: `${prefix}/pieceGroup/listGroup`
8
+  }
9
+}
10
+
11
+export default Api

+ 42
- 0
src/util/PublicMethod/index.js Просмотреть файл

@@ -0,0 +1,42 @@
1
+import qs from 'qs'
2
+const ToolClass = {
3
+  ReplaceURLParams (url, params) {
4
+    const args = { ...(params || {}), org: 'MQ' }
5
+    return Object.keys(args).reduce((acc, k) => { // 此方法对每个元素进行处理
6
+      const re = new RegExp(`:${k}(?!w)`, 'i')
7
+      return acc.replace(re, args[k])
8
+    }, url)
9
+  },
10
+  WxRequest (config) { // 网络请求
11
+    let urlData = qs.stringify(config.urlData)
12
+    let queryData = qs.stringify(config.queryData)
13
+    // 判断是通过斜杠传参
14
+    if (config.url.indexOf(':') > -1) {
15
+      if (typeof config.urlData === 'object') {
16
+        config.url = this.ReplaceURLParams(config.url, config.urlData)
17
+      } else {
18
+        config.url = config.url.slice(0, config.url.indexOf(':')) + urlData
19
+      }
20
+    }
21
+    if (queryData) {
22
+      config.url += '?' + queryData
23
+    }
24
+    wx.request({
25
+      url: `http://121.40.96.72:91${config.url}`,
26
+      method: config.method,
27
+      ...(config.data || {}),
28
+      success: (res) => {
29
+        if (config.success !== undefined) {
30
+          config.success(res)
31
+        }
32
+      },
33
+      fail: (res) => {
34
+        if (config.error !== undefined) {
35
+          config.error(res)
36
+        }
37
+      }
38
+    })
39
+  }
40
+}
41
+
42
+export default ToolClass