my.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <!-- 个人信息 -->
  3. <view class="page-container">
  4. <!-- 背景图片 -->
  5. <image class="bg-image " src="@/static/images/bg.png" mode="aspectFill"></image>
  6. <!-- 内容区域 -->
  7. <view class="content-area">
  8. <!-- 访客信息表单 -->
  9. <!-- <view class="visitor-form" @tap="goLogin">-->
  10. <view class="visitor-form" >
  11. <view v-if="isLogin">
  12. <view class="form-item">
  13. <text class="label">姓名</text>
  14. <text class="value">{{user.nickName || '-'}}</text>
  15. </view>
  16. <view class="form-item">
  17. <text class="label">手机号</text>
  18. <text class="value">{{user.phonenumber || '-'}}</text>
  19. </view>
  20. <view class="form-item">
  21. <text class="label">公司名称</text>
  22. <text class="value">{{user.dept && user.dept.deptName || '-'}}</text>
  23. </view>
  24. <view class="form-item">
  25. <text class="label">部门</text>
  26. <text class="value">{{user.dept && user.dept.deptName || '-'}}</text>
  27. </view>
  28. </view>
  29. <view v-else class="login-container">
  30. <view class="login-prompt">
  31. <text class="login-title">欢迎使用知己访客</text>
  32. <text class="login-subtitle">登录后可使用更多功能</text>
  33. </view>
  34. <view class="login-button" @tap="goLogin">
  35. <text class="login-text">点击登录</text>
  36. <text class="login-arrow"></text>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- <view v-if="isLogin" class="edit-button" @tap="goUserDetail">-->
  41. <!-- <text class="edit-text">编辑</text>-->
  42. <!-- </view>-->
  43. <!-- 退出登录按钮 -->
  44. <view v-if="isLogin" class="logout-button" @tap="handlerLogout">
  45. <text class="logout-text">退出登录</text>
  46. </view>
  47. <!-- 功能菜单 -->
  48. </view>
  49. <uni-popup ref="checkLoginDialog" type="dialog">
  50. <uni-popup-dialog type="warn" cancelText="继续浏览" confirmText="确认" title="提示" content="体验更多功能,请先登录"
  51. @confirm="goLogin()"></uni-popup-dialog>
  52. </uni-popup>
  53. </view>
  54. </template>
  55. <script>
  56. import {
  57. getUserInfo, wxLogin,
  58. } from '../../config/api';
  59. import {
  60. mapActions,
  61. mapGetters
  62. } from 'vuex';
  63. import store from '@/store';
  64. import customNavbar from '../../components/custom-navbar/custom-navbar.vue'
  65. import {
  66. shareImg
  67. } from '@/common/config.js'
  68. export default {
  69. data() {
  70. return {
  71. user: {}
  72. }
  73. },
  74. computed: {
  75. ...mapGetters(['isLogin', 'userInfo', 'access_token', 'refresh_token'])
  76. },
  77. onLoad() {
  78. },
  79. onShow() {
  80. this.getUserInfo()
  81. },
  82. // 微信小程序分享配置
  83. onShareAppMessage() {
  84. return {
  85. title: `邀请您加入知己访客`,
  86. path: `/pages/index/index`,
  87. imageUrl: shareImg // 分享图片,需要添加
  88. }
  89. },
  90. onShareTimeline(res) {
  91. let that = this;
  92. let shareInfo = store.state.vuex_shareInfo;
  93. let query = shareInfo.query;
  94. //携带当前页面资源ID参数
  95. let currentPage = getCurrentPages()[getCurrentPages().length - 1];
  96. let options = currentPage.options;
  97. if (JSON.stringify(options) != '{}' && options.id) {
  98. query += `&id=${options.id}`;
  99. }
  100. return {
  101. title: shareInfo.title,
  102. query: query,
  103. imageUrl: shareImg,
  104. success(res) {
  105. uni.showToast({
  106. title: '分享成功'
  107. })
  108. },
  109. fail(res) {
  110. uni.showToast({
  111. title: '分享失败',
  112. icon: 'none'
  113. })
  114. },
  115. complete() {}
  116. }
  117. },
  118. methods: {
  119. ...mapActions(['logout', 'setToken', 'setUserInfo']),
  120. // async detail() {
  121. // const data = await memberDetail()
  122. // if (data.code == 200) {
  123. // this.user = data.data
  124. // uni.setStorageSync('user', this.user)
  125. // }
  126. // },
  127. async getUserInfo() {
  128. const user = uni.getStorageSync('user');
  129. if (user) {
  130. this.user = user;
  131. }
  132. },
  133. // 登录处理
  134. async goLogin() {
  135. console.log(this.isLogin)
  136. if (!this.isLogin) {
  137. try {
  138. // 1. 尝试微信授权登录
  139. const loginRes = await new Promise((resolve, reject) => {
  140. uni.login({
  141. provider: 'weixin',
  142. success: (res) => {
  143. if (res.code) {
  144. resolve(res); // 成功获取 code
  145. } else {
  146. reject(new Error('未获取到微信授权码'));
  147. }
  148. },
  149. fail: (err) => {
  150. reject(new Error('微信授权失败'));
  151. }
  152. });
  153. });
  154. // 2. 调用微信登录接口
  155. const wxRes = await wxLogin({ code: loginRes.code });
  156. console.log('微信登录成功:', wxRes);
  157. // 3. 登录成功后的逻辑(如存储用户信息、跳转首页等)
  158. if (wxRes && wxRes.message === "登录成功"&& wxRes.user) {
  159. uni.setStorageSync('user', wxRes.data);
  160. if (wxRes.user) {
  161. uni.setStorageSync('user', wxRes.user);
  162. }
  163. // 更新store状态
  164. this.$store.commit('isLogin', true);
  165. this.isEmployeeLogin = true
  166. this.getUserInfo()
  167. // uni.switchTab({
  168. // url: '/pages/tabbar/home' // 替换为实际首页路径
  169. // });
  170. } else {
  171. console.log('微信登录接口返回异常');
  172. uni.navigateTo({
  173. url: '/pagesA/public/phone-login'
  174. });
  175. }
  176. } catch (error) {
  177. console.error('登录失败:', error);
  178. // 4. 微信授权或登录失败,跳转到手机号登录页
  179. // uni.navigateTo({
  180. // url: '/pagesA/public/phone-login'
  181. // });
  182. }
  183. // uni.navigateTo({
  184. // url: '/pagesA/public/login'
  185. // });
  186. } else {
  187. this.$route('/pagesA/public/login');
  188. }
  189. },
  190. // 跳转用户信息
  191. goUserDetail() {
  192. uni.navigateTo({
  193. url: '/pagesA/user/index'
  194. });
  195. },
  196. // 退出登录
  197. handlerLogout() {
  198. uni.showModal({
  199. title: '提示',
  200. content: '确定要退出登录吗?',
  201. success: (res) => {
  202. if (res.confirm) {
  203. // 清除缓存
  204. uni.removeStorageSync('access_token');
  205. uni.removeStorageSync('user');
  206. // 调用vuex的logout方法
  207. this.logout();
  208. uni.showToast({
  209. title: '退出成功',
  210. icon: 'success'
  211. });
  212. // 刷新当前页面
  213. this.user = {};
  214. }
  215. }
  216. });
  217. }
  218. },
  219. }
  220. </script>
  221. <style>
  222. /* 页面容器 */
  223. .page-container {
  224. min-height: 100vh;
  225. background-color: #F5F5F5;
  226. }
  227. /* 背景图片 */
  228. .bg-image {
  229. top: 0;
  230. left: 0;
  231. width: 100%;
  232. height: 300rpx;
  233. z-index: 0;
  234. }
  235. /* 内容区域 */
  236. .content-area {
  237. position: relative;
  238. z-index: 1;
  239. padding: 32rpx;
  240. }
  241. /* 访客信息表单 */
  242. .visitor-form {
  243. background: #FFFFFF;
  244. border-radius: 24rpx;
  245. padding: 0 32rpx;
  246. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  247. }
  248. .form-item {
  249. display: flex;
  250. align-items: center;
  251. min-height: 120rpx;
  252. border-bottom: 1rpx solid #F5F5F5;
  253. }
  254. .form-item:last-child {
  255. border-bottom: none;
  256. }
  257. .label {
  258. width: 140rpx;
  259. font-size: 28rpx;
  260. color: #999999;
  261. }
  262. .value {
  263. flex: 1;
  264. font-size: 28rpx;
  265. color: #333333;
  266. }
  267. /* 未登录状态样式 */
  268. .login-container {
  269. padding: 40rpx 0;
  270. display: flex;
  271. flex-direction: column;
  272. align-items: center;
  273. justify-content: center;
  274. gap: 40rpx;
  275. }
  276. .login-prompt {
  277. display: flex;
  278. flex-direction: column;
  279. align-items: center;
  280. gap: 16rpx;
  281. }
  282. .login-title {
  283. font-size: 36rpx;
  284. color: #333333;
  285. font-weight: 600;
  286. }
  287. .login-subtitle {
  288. font-size: 28rpx;
  289. color: #999999;
  290. }
  291. .login-button {
  292. width: 100%;
  293. height: 88rpx;
  294. background: linear-gradient(90deg, #FF5B05 0%, #FF8E3C 100%);
  295. border-radius: 44rpx;
  296. display: flex;
  297. align-items: center;
  298. justify-content: center;
  299. gap: 8rpx;
  300. box-shadow: 0 4rpx 16rpx rgba(255, 91, 5, 0.2);
  301. }
  302. .login-text {
  303. color: #FFFFFF;
  304. font-size: 32rpx;
  305. font-weight: 500;
  306. }
  307. .login-arrow {
  308. color: #FFFFFF;
  309. font-size: 32rpx;
  310. font-weight: 500;
  311. margin-left: 8rpx;
  312. }
  313. .edit-button {
  314. margin: 80rpx 32rpx 0;
  315. height: 88rpx;
  316. display: flex;
  317. align-items: center;
  318. justify-content: center;
  319. border: 2rpx solid #FF5B05;
  320. border-radius: 44rpx;
  321. }
  322. .edit-text {
  323. color: #FF5B05;
  324. font-size: 32rpx;
  325. }
  326. .logout-button {
  327. margin: 30rpx 32rpx 0;
  328. height: 88rpx;
  329. display: flex;
  330. align-items: center;
  331. justify-content: center;
  332. background: #FF4748;
  333. border-radius: 44rpx;
  334. }
  335. .logout-text {
  336. color: #FFFFFF;
  337. font-size: 32rpx;
  338. }
  339. </style>