Bläddra i källkod

+ 报名页面

chen.cheng 11 månader sedan
förälder
incheckning
4d1a905e7c

+ 25 - 1
common/api.js

@@ -24,8 +24,32 @@ export const putUsrRegist = (params) => {
     return Promise.reject('未登录');
   }
   return http.put('/cp/user', params, {
-    headers: {
+    header: {
       Authorization: `Bearer ${token}`,
     },
   });
 };
+
+export const fetchEnterpriseList = (params = {}) => http.get(
+  '/cp/enterprise/list', {
+    params: {
+      pageNum: 1,
+      pageSize: 999,
+      ...params,
+    },
+    header: {
+      Authorization: `Bearer ${getToken()}`,
+    },
+  });
+
+export const fetchEnterpriseTripList = (params = {}) => http.get(
+  '/cp/enterpriseTripInfo/list', {
+    params: {
+      pageNum: 1,
+      pageSize: 999,
+      ...params,
+    },
+    header: {
+      Authorization: `Bearer ${getToken()}`,
+    },
+  });

+ 5 - 7
components/SingleDropList/index.vue

@@ -38,11 +38,7 @@ export default {
     placeholder: {
       type: String,
       default: '选择参会企业',
-    },
-    onChange: {
-      type: Function,
-      default: () => {},
-    },
+    }
   },
   data() {
     return {
@@ -56,7 +52,9 @@ export default {
       handler(val) {
         if (val && val.length > 0 && this.defaultValue) {
           const defItem = val.find((item) => item.value === this.defaultValue);
-          this.name = defItem.name;
+          if (defItem) {
+            this.name = defItem.name;
+          }
         }
       },
       immediate: true,
@@ -69,7 +67,7 @@ export default {
   methods: {
     onSelect(item) {
       this.name = item.name;
-      this.onChange(item);
+      this.$emit('onChange', item);
     },
   },
 };

+ 6 - 8
pages/tabbar/index/index.vue

@@ -15,7 +15,7 @@
         <u-grid-item
             v-for="(baseListItem,baseListIndex) in baseList"
             :key="baseListIndex"
-            @click="onItemClick(baseListItem)"
+            @click="$u.throttle(()=>onItemClick(baseListItem), 500)"
         >
           <view class="grid-item-icon" :style="[baseListItem.style]">
             <image :src="baseListItem.icon"></image>
@@ -53,15 +53,13 @@ export default {
   data() {
     return {
       keyword: '',
-      list: [
-      ],
+      list: [],
       msg: [],
-      baseList: [
-      ],
+      baseList: [],
       indexList: [],
       styleObj: {
-        "backgroundColor": "#000"
-      }
+        'backgroundColor': '#000',
+      },
     };
   },
   onLoad() {
@@ -91,7 +89,7 @@ export default {
           title: item.title,
           date: item.createTime,
         };
-        });
+      });
     },
     async loadMsg() {
       let result = [];

+ 19 - 18
pages/tabbar/my/index.vue

@@ -33,24 +33,25 @@ import { getUserInfo } from '@/util';
 
 export default {
   components: { AuthWrap },
-		data() {
-			return {
-        userInfo: {},
-        src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg',
-      }
-		},
-		onLoad() {
-      this.$refs.authWrap.reloadPage();
-      this.userInfo = getUserInfo();
-		},
-		methods: {
-		},
-		onShareAppMessage() {
-			return {
-				title: 'First UI组件库'
-			}
-		}
-	}
+  data() {
+    return {
+      userInfo: {},
+      src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg',
+    };
+  },
+  onLoad() {
+  },
+  onShow() {
+    this.$refs.authWrap.reloadPage();
+    this.userInfo = getUserInfo();
+  },
+  methods: {},
+  onShareAppMessage() {
+    return {
+      title: 'First UI组件库',
+    };
+  },
+};
 </script>
 
 <style lang="scss" src="./index.scss">

+ 12 - 49
pasb/pages/login/index.vue

@@ -16,7 +16,7 @@
 <script>
 
 import { ICON_CFG } from '@/common/EnumConst';
-import { getImageUrl, setStorageObj } from '@/util';
+import { getImageUrl, setStorageObj, syncWxlogin } from '@/util';
 
 export default {
   name: 'login',
@@ -33,11 +33,20 @@ export default {
   methods: {
     getImageUrl,
     // 获取用户信息
-    getUserInfo(e) {
+    async getUserInfo(e) {
       if (e.mp.detail.userInfo) {
         this.userInfo = e.mp.detail.userInfo;
         this.hasUserInfo = true;
-        this.login();
+        const {
+          success,
+          data,
+        } = await syncWxlogin();
+        if (success) {
+          // 将用户信息和session存储到本地
+          setStorageObj('userInfo', data.user);
+          setStorageObj('token', data.token);
+          this.realoadPage();
+        }
       } else {
         uni.showModal({
           title: '警告',
@@ -52,52 +61,6 @@ export default {
         });
       }
     },
-    // 登录并获取用户信息
-    login() {
-      uni.login({
-        provider: 'weixin',
-        success: (loginRes) => {
-          // 登录成功,获取用户code
-          const { code } = loginRes;
-          // 发送code到后台换取openId, sessionKey, unionId
-          uni.request({
-            url: `${process.env.UNI_API_PREFIX}/cp/usr/wx/login`, // 你的登录API地址
-            method: 'POST',
-            data: {
-              code,
-              ...this.userInfo,
-            },
-            success: (res) => {
-              if (res.data && res.data.code === 200) {
-                const { data } = res.data;
-                // 将用户信息和session存储到本地
-                setStorageObj('userInfo', data.user);
-                setStorageObj('token', data.token);
-                this.realoadPage();
-              } else {
-                uni.showToast({
-                  title: '登录失败',
-                  icon: 'none',
-                });
-              }
-            },
-            fail: () => {
-              uni.showToast({
-                title: '请求失败',
-                icon: 'none',
-              });
-            },
-          });
-        },
-        fail: (err) => {
-          console.log('uni.login 接口调用失败,将无法正常使用开放接口等服务', err);
-          uni.showToast({
-            title: '登录失败',
-            icon: 'none',
-          });
-        },
-      });
-    },
     realoadPage() {
       let pages = getCurrentPages();  //获取当前页面
       let beforePage = pages[pages.length - 2];  //获取上一个页面的实例

+ 33 - 5
pasb/pages/regist/index.vue

@@ -67,9 +67,9 @@
                 marginLeft: '20rpx'
               }"
                 defaultValue="1"
-                :src="sexList"
+                :src="enterpriseList"
                 placeholder="请选择参会企业"
-                :on-change="enterpriseSelect"
+                @onChange="enterpriseSelect"
             >
             </SingleDropList>
           </u-form-item>
@@ -84,9 +84,9 @@
                 marginLeft: '20rpx'
               }"
                 defaultValue="1"
-                :src="sexList"
+                :src="tripList"
                 placeholder="请选择参会行程"
-                :on-change="enterpriseSelect"
+                @onChange="enterpriseTripSelect"
             >
             </SingleDropList>
           </u-form-item>
@@ -111,7 +111,7 @@
 
 <script>
 
-import { putUsrRegist } from '@/common/api';
+import { fetchEnterpriseList, fetchEnterpriseTripList, putUsrRegist } from '@/common/api';
 import { ICON_CFG } from '@/common/EnumConst';
 import AuthWrap from '@/components/AuthComp/index.vue';
 import SingleDropList from '@/components/SingleDropList/index.vue';
@@ -149,6 +149,8 @@ export default {
           name: '保密',
         },
       ],
+      enterpriseList: [],
+      tripList: [],
       rules: {
         'userInfo.name': {
           type: 'string',
@@ -176,6 +178,7 @@ export default {
     if (user) {
       this.model1.userInfo.name = user.usrName;
     }
+    this.init();
   },
   onReady() {
     //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
@@ -188,6 +191,31 @@ export default {
       this.model1.userInfo.enterpriseName = enterprise.name;
       this.$refs.uForm.validateField('userInfo.enterpriseId');
     },
+    enterpriseTripSelect(trip) {
+
+    },
+    async init() {
+      const {
+        code: enterpriseCode,
+        rows: enterpriseData,
+      } = await fetchEnterpriseList();
+      const {
+        code: tripCode,
+        rows: tripData,
+      } = await fetchEnterpriseTripList();
+      this.enterpriseList = enterpriseData.map(item => {
+        return {
+          name: item.enterpriseName,
+          value: item.id,
+        };
+      });
+      this.tripList = tripData.map(item => {
+        return {
+          name: item.tripName,
+          value: item.id,
+        };
+      });
+    },
     onSubmit() {
       this.loading = true;
       this.$refs.uForm.validate().then(res => {

+ 93 - 0
util/index.js

@@ -84,6 +84,99 @@ export const authLogin = (callback) => {
   callback(user);
 };
 
+export const syncWxlogin = (userInfo = {}) => {
+  return new Promise((resolve, reject) => {
+    // uni.login非异步,所以用Promise包装
+    uni.login({
+      provider: 'weixin',
+      success: loginRes => {
+        // 登录成功,获取用户code
+        const { code } = loginRes;
+        // 发送code到后台换取openId, sessionKey, unionId
+        uni.request({
+          url: `${process.env.UNI_API_PREFIX}/cp/usr/wx/login`, // 你的登录API地址
+          method: 'POST',
+          data: {
+            code,
+            ...userInfo,
+          },
+          success: (res) => {
+            if (res.data && res.data.code === 200) {
+              const { data } = res.data;
+              resolve({
+                success: true,
+                data,
+              });
+            } else {
+              uni.showToast({
+                title: '登录失败',
+                icon: 'none',
+              });
+              resolve({
+                success: false,
+                msg: '登录失败',
+              });
+            }
+          },
+          fail: (err) => {
+            uni.showToast({
+              title: '请求失败',
+              icon: 'none',
+            });
+            reject(err);
+          },
+        });
+
+      },
+      fail: err => {
+        reject(err);
+      },
+    });
+  });
+};
+export const wxlogin = (callback) => {
+  uni.login({
+    provider: 'weixin',
+    success: (loginRes) => {
+      // 登录成功,获取用户code
+      const { code } = loginRes;
+      // 发送code到后台换取openId, sessionKey, unionId
+      uni.request({
+        url: `${process.env.UNI_API_PREFIX}/cp/usr/wx/login`, // 你的登录API地址
+        method: 'POST',
+        data: {
+          code,
+          ...this.userInfo,
+        },
+        success: (res) => {
+          if (res.data && res.data.code === 200) {
+            const { data } = res.data;
+            callback(data);
+          } else {
+            uni.showToast({
+              title: '登录失败',
+              icon: 'none',
+            });
+          }
+        },
+        fail: () => {
+          uni.showToast({
+            title: '请求失败',
+            icon: 'none',
+          });
+        },
+      });
+    },
+    fail: (err) => {
+      console.log('uni.login 接口调用失败,将无法正常使用开放接口等服务', err);
+      uni.showToast({
+        title: '登录失败',
+        icon: 'none',
+      });
+    },
+  });
+};
+
 export const fileIcon = (fileSuffix) => {
   let icon = '';
   if (FILE_ICON[fileSuffix]) {