Jelajahi Sumber

+ 与会企业行程

chen.cheng 11 bulan lalu
induk
melakukan
fc3cb96269
7 mengubah file dengan 337 tambahan dan 146 penghapusan
  1. 1 0
      common/EnumConst.js
  2. 99 86
      pages.json
  3. 57 0
      pages/tabbar/my/index.scss
  4. 33 60
      pages/tabbar/my/index.vue
  5. 26 0
      pasb/pages/login/index.scss
  6. 101 0
      pasb/pages/login/index.vue
  7. 20 0
      util/index.js

+ 1 - 0
common/EnumConst.js

@@ -4,4 +4,5 @@ export const COMP_CODE = {
 };
 export const ICON_CFG = {
   file_icon: '/profile/upload/2024/08/17/file_icon_20240817121536A002.svg',
+  login_bg: '/profile/upload/2024/08/17/head-bg_20240817230007A002.png',
 };

+ 99 - 86
pages.json

@@ -1,88 +1,101 @@
 {
-	"pages": [
-		{
-			"path": "pages/tabbar/index/index",
-			"style": {
-				"navigationBarTitleText": "交通强国"
-			}
-		},
-		{
-			"path": "pages/tabbar/news/index",
-			"style": {
-				"navigationBarTitleText": "资讯"
-			}
-		},
-		{
-			"path": "pages/tabbar/my/index",
-			"style": {
-				"navigationBarTitleText": "我的"
-			}
-		}
-	],
-	"subPackages": [
-		{
-			"root": "pasb",
-			"name": "sub-1",
-			"pages": [
-				{
-					"path": "pages/detail/index",
-					"style": {
-						"navigationBarTitleText": "最新资讯"
-					}
-				}
-			]
-		},
-		{
-			"root": "pasb",
-			"name": "sub-2",
-			"pages": [
-				{
-					"path": "pages/file/index",
-					"style": {
-						"navigationBarTitleText": "交流材料汇编"
-					}
-				}
-			]
-		}
-	],
-	"globalStyle": {
-		"navigationBarTextStyle": "#fefefe",
-		"navigationBarBackgroundColor": "#005598",
-		"backgroundColor": "#f2f2f2"
-	},
-	"tabBar": {
-		"color": "#7f8389",
-		"selectedColor": "#465CFF",
-		"backgroundColor": "#f7f7fa",
-		"list": [{
-				"pagePath": "pages/tabbar/index/index",
-				"text": "首页",
-				"iconPath": "static/images/tabbar/assembly_default_3x.png",
-				"selectedIconPath": "static/images/tabbar/assembly_selected_3x.png"
-			},
-			{
-				"pagePath": "pages/tabbar/news/index",
-				"text": "资讯",
-				"iconPath": "static/images/tabbar/layout_default_3x.png",
-				"selectedIconPath": "static/images/tabbar/layout_selected_3x.png"
-			},
-			{
-				"pagePath": "pages/tabbar/my/index",
-				"text": "我的",
-				"iconPath": "static/images/tabbar/my_default_3x.png",
-				"selectedIconPath": "static/images/tabbar/my_selected_3x.png"
-			}
-		]
-	},
-	"condition" : { //模式配置,仅开发期间生效
-		"current": 0, //当前激活的模式(list 的索引项)
-		"list": [
-			{
-				"name": "交流材料汇编", //模式名称
-				"path": "pages/tabbar/my/index", //启动页面,必选
-				"query": "" //启动参数,在页面的onLoad函数里面得到
-			}
-		]
-	},
-	"resizable": true
+  "pages": [
+    {
+      "path": "pages/tabbar/index/index",
+      "style": {
+        "navigationBarTitleText": "交通强国"
+      }
+    },
+    {
+      "path": "pages/tabbar/news/index",
+      "style": {
+        "navigationBarTitleText": "资讯"
+      }
+    },
+    {
+      "path": "pages/tabbar/my/index",
+      "style": {
+        "navigationBarTitleText": "我的"
+      }
+    }
+  ],
+  "subPackages": [
+    {
+      "root": "pasb",
+      "name": "sub-1",
+      "pages": [
+        {
+          "path": "pages/detail/index",
+          "style": {
+            "navigationBarTitleText": "最新资讯"
+          }
+        }
+      ]
+    },
+    {
+      "root": "pasb",
+      "name": "sub-2",
+      "pages": [
+        {
+          "path": "pages/file/index",
+          "style": {
+            "navigationBarTitleText": "交流材料汇编"
+          }
+        }
+      ]
+    },
+    {
+      "root": "pasb",
+      "name": "sub-3",
+      "pages": [
+        {
+          "path": "pages/login/index",
+          "style": {
+            "navigationBarTitleText": "微信登录"
+          }
+        }
+      ]
+    }
+  ],
+  "globalStyle": {
+    "navigationBarTextStyle": "#fefefe",
+    "navigationBarBackgroundColor": "#005598",
+    "backgroundColor": "#f2f2f2"
+  },
+  "tabBar": {
+    "color": "#7f8389",
+    "selectedColor": "#465CFF",
+    "backgroundColor": "#f7f7fa",
+    "list": [
+      {
+        "pagePath": "pages/tabbar/index/index",
+        "text": "首页",
+        "iconPath": "static/images/tabbar/assembly_default_3x.png",
+        "selectedIconPath": "static/images/tabbar/assembly_selected_3x.png"
+      },
+      {
+        "pagePath": "pages/tabbar/news/index",
+        "text": "资讯",
+        "iconPath": "static/images/tabbar/layout_default_3x.png",
+        "selectedIconPath": "static/images/tabbar/layout_selected_3x.png"
+      },
+      {
+        "pagePath": "pages/tabbar/my/index",
+        "text": "我的",
+        "iconPath": "static/images/tabbar/my_default_3x.png",
+        "selectedIconPath": "static/images/tabbar/my_selected_3x.png"
+      }
+    ]
+  },
+  "condition": {
+    "current": 0,
+    "list": [
+      {
+        "name": "交流材料汇编",
+        "path": "pages/tabbar/my/index",
+        "query": ""
+      }
+    ]
+  },
+  "resizable": true
 }

+ 57 - 0
pages/tabbar/my/index.scss

@@ -0,0 +1,57 @@
+@import "../../../common/common.scss";
+
+.fui-wrap {
+  width: 100%;
+  height: 100%;
+  display: flex;
+  flex-direction: column;
+  justify-content: top;
+  background-color: #79797938;
+
+  .user-info-bg {
+    width: 100%;
+    height: 100rpx;
+    background-color: #005598;
+  }
+
+  .ctl-container {
+    margin-top: -70rpx;
+    z-index: 1;
+    display: flex;
+    flex-direction: column;
+    justify-content: flex-start;
+    align-items: center;
+    >view{
+      width: 90%;
+      padding: 20rpx 20rpx;
+      background-color: #fefefe;
+      box-sizing: border-box;
+      border-radius: 20rpx;
+      &:not(:first-child){
+        margin-top: 40rpx;
+      }
+    }
+    .user-info-content {
+      height: 200rpx;
+      display: flex;
+      align-items: center;
+      justify-content: flex-start;
+      .user-info{
+        height: 100%;
+        display: flex;
+        flex-direction: column;
+        align-items: flex-start;
+        justify-content: space-around;
+        margin-left: 20rpx;
+      }
+    }
+    .ctl-panel{
+      height: 250rpx;
+    }
+  }
+}
+
+page {
+  height: 100%;
+}
+

+ 33 - 60
pages/tabbar/my/index.vue

@@ -1,68 +1,48 @@
 <template>
 	<view class="fui-wrap">
-		<u-button
-		    text="默认按钮"
-		    size="normal"
-		    type="info"
-			@click="onClick"
-		></u-button>
+    <view class="user-info-bg">
+    </view>
+    <view class="ctl-container">
+      <view class="user-info-content">
+        <view class="user-info-img">
+          <u-avatar :src="src" shape="circle" :size="60"></u-avatar>
+        </view>
+        <view class="user-info">
+          <view>
+            微信用户
+          </view>
+          <view>
+            18120188135
+          </view>
+        </view>
+      </view>
+
+      <view class="ctl-panel">
+
+      </view>
+    </view>
 	</view>
 </template>
 
 <script>
 
-  export default {
+import { getUserInfo } from '@/util';
+
+export default {
 		data() {
 			return {
-
-			}
+        src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg',
+      }
 		},
 		onLoad() {
-      // #ifdef MP-WEIXIN
-      wx.login({
-        success: function(res) {
-          wx.request({
-            url: "https://api.weixin.qq.com/sns/jscode2session",
-            data: {
-              appid: process.env.UNI_WX_APPID,
-              secret: process.env.UNI_WX_AS,
-              js_code: res.code,
-              grant_type: "authorization_code",
-            },
-            success: function(response) {
-              const openid = response.data.openid;
-              console.log("获取到的code:", res.code, "获取到的openid:", openid);
-              // 使用登录凭证获取用户信息
-              uni.getUserInfo({
-                provider: 'weixin',
-                success: function (infoRes) {
-                  console.log(infoRes.userInfo); // 打印用户信息
-                  console.log('用户昵称为: ' + infoRes.userInfo.nickName); // 打印用户昵称
-                  // 在这里,你可以将用户的头像和昵称保存到本地或者发送到后端进行处理
-                  // infoRes.userInfo.avatarUrl是用户的头像链接
-                  // infoRes.userInfo.nickName是用户的昵称
-                }
-              });
-            }
-          })
-        }
-      })
-      // #endif
+      // const user = getUserInfo();
+      // if (!user) {
+      //   uni.navigateTo({
+      //     url: '/pasb/pages/login/index',
+      //   });
+      // }
 		},
 		methods: {
-      onClick() {
-				uni.navigateTo({
-          url: '/pasb/pages/file/index'
-        })
-			},
-			getUserInfo() {
-				uni.getUserProfile({
-					desc: '获取用户信息',
-					success: (res) => {
-						console.log(res);
-					}
-				})
-			},
 		},
 		onShareAppMessage() {
 			return {
@@ -72,12 +52,5 @@
 	}
 </script>
 
-<style>
-	.fui-banner__box {
-		width: 100%;
-		min-height: 538rpx;
-		position: relative;
-		background-color: #EDF9FF;
-	}
-
+<style lang="scss" src="./index.scss">
 </style>

+ 26 - 0
pasb/pages/login/index.scss

@@ -0,0 +1,26 @@
+.login-container {
+  width: 100%;
+  height: 100%;
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+  align-items: center;
+  .login-btn{
+    border: none;
+    background-color: #548cf7;
+    color: #ffffff;
+    font-size: 32rpx;
+    width: 600rpx;
+    height: 80rpx;
+    border-radius: 50px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    .u-icon{
+      margin-right: 20rpx;
+    }
+  }
+}
+page {
+  height: 100%;
+}

+ 101 - 0
pasb/pages/login/index.vue

@@ -0,0 +1,101 @@
+<template>
+  <view
+      class="login-container"
+      :style="{
+         background: `url(${getImageUrl(ICON_CFG.login_bg)}) no-repeat `,
+         backgroundSize: '100%',
+       }"
+  >
+    <button class="login-btn" open-type="getUserInfo" @getuserinfo="getUserInfo">
+      <u-icon name="weixin-fill" color="#fefefe" size="28"></u-icon>
+      一键微信登录
+    </button>
+  </view>
+</template>
+
+<script>
+
+import { ICON_CFG } from '@/common/EnumConst';
+import { getImageUrl, setStorageObj } from '@/util';
+
+export default {
+  name: 'login',
+  props: {},
+  data() {
+    return {
+      ICON_CFG,
+    };
+  },
+  created() {
+  },
+  onLoad() {
+  },
+  methods: {
+    getImageUrl,
+    // 获取用户信息
+    getUserInfo(e) {
+      if (e.mp.detail.userInfo) {
+        this.userInfo = e.mp.detail.userInfo;
+        this.hasUserInfo = true;
+        this.login();
+      } else {
+        uni.showModal({
+          title: '警告',
+          content: '您点击了拒绝授权,将无法进入小程序,请授权之后再进入!',
+          showCancel: false,
+          confirmText: '返回授权',
+          success: function (res) {
+            if (res.confirm) {
+              console.log('用户点击了“返回授权”');
+            }
+          },
+        });
+      }
+    },
+    // 登录并获取用户信息
+    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) {
+                // 将用户信息和session存储到本地
+                setStorageObj('userInfo', res.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',
+          });
+        },
+      });
+    },
+  },
+};
+</script>
+<style lang="scss" src="./index.scss" />;

+ 20 - 0
util/index.js

@@ -42,3 +42,23 @@ export const viewFileFn = (fileUrl, fileName, fileSuffix) => { // 文件url 文
     },
   });
 };
+export const setStorageObj = (key, value = {}) => {
+  const json = JSON.stringify(value);
+  uni.setStorageSync(key, json);
+};
+
+export const getStorageObj = (key) => {
+  const json = uni.getStorageSync(key);
+  if (!json) {
+    return null;
+  }
+  return JSON.parse(json);
+};
+
+export const getUserInfo = () => {
+  const userInfo = getStorageObj('userInfo');
+  if (!userInfo) {
+    return null;
+  }
+  return userInfo;
+};