图书馆小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

314 lines
8.2 KiB

2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
  1. <template>
  2. <view style="padding-bottom: 20px;">
  3. <view class="top-user-bar">
  4. <image class="top-bar-bg" src="@/static/images/mingqi-beij@2x.png" mode="aspectFill"></image>
  5. <view class="user-info">
  6. <image
  7. class="avatar"
  8. :src="userInfo.avatarUrl || '/static/images/default-avatar.png'"
  9. mode="aspectFill"
  10. ></image>
  11. <view class="user-info-text">
  12. <text class="user-name">{{ userInfo.nickName || '未登录' }}</text>
  13. <text class="user-card">{{ userInfo.cardNo || '' }}</text>
  14. </view>
  15. </view>
  16. <view class="user-menu">
  17. <view class="menu-item" @click="toCheckLogin('收藏')">
  18. <image class="menu-icon" src="@/static/images/menu-sc.png" mode="scaleToFill" />
  19. <text class="menu-txt">收藏</text>
  20. </view>
  21. <view class="menu-item" @click="toCheckLogin('借阅')">
  22. <image class="menu-icon" src="@/static/images/menu-jy.png" mode="scaleToFill" />
  23. <text class="menu-txt">借阅</text>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="submenu-box">
  28. <view class="submenu-item" @click="toCheckLogin('我的留言')">
  29. <uni-icons custom-prefix="iconfont" type="icon-liuyan" size="20"></uni-icons>
  30. <text class="left-txt">我的留言</text>
  31. </view>
  32. <view class="submenu-item" @click="toCheckLogin('个人资料')">
  33. <uni-icons custom-prefix="iconfont" type="icon-shezhi" size="20"></uni-icons>
  34. <text class="left-txt">个人资料</text>
  35. </view>
  36. <view class="submenu-item" @click="toCheckLogin('修改密码')">
  37. <uni-icons custom-prefix="iconfont" type="icon-xiugai" size="20"></uni-icons>
  38. <text class="left-txt">修改密码</text>
  39. </view>
  40. <view class="submenu-item" @click="toCheckLogin('挂失读者证')">
  41. <uni-icons custom-prefix="iconfont" type="icon-UIsheji_menjinxitong-28" size="20"></uni-icons>
  42. <text class="left-txt">挂失读者证</text>
  43. </view>
  44. <view v-if="!!isBindLibraryCard" class="submenu-item" @click="toLogOut()">
  45. <uni-icons custom-prefix="iconfont" type="icon-tuichu" size="20"></uni-icons>
  46. <text class="left-txt">退出账号</text>
  47. </view>
  48. </view>
  49. <view>
  50. <uni-popup ref="alertDialog" type="dialog">
  51. <uni-popup-dialog
  52. type="info" cancelText="取消" confirmText="确定"
  53. title="提示" content="请您绑定读者证!"
  54. @confirm="dialogConfirm" @close="dialogClose">
  55. </uni-popup-dialog>
  56. </uni-popup>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. export default {
  62. data() {
  63. return {
  64. token: "",
  65. userInfo: {},
  66. isBindLibraryCard: false
  67. };
  68. },
  69. onLoad() {
  70. // this.loadUser()
  71. this.checkLoginStatus();
  72. },
  73. onShow() {
  74. // this.loadUser()
  75. this.checkLoginStatus();
  76. },
  77. methods: {
  78. checkLoginStatus() {
  79. this.loadUser();
  80. this.isBindLibraryCard = !!this.token;
  81. },
  82. // 统一读取用户信息
  83. loadUser() {
  84. this.token = uni.getStorageSync("token") || ""
  85. this.userInfo = uni.getStorageSync("user-info") || {}
  86. },
  87. // ✅ 核心:点击任意项都先校验登录
  88. toCheckLogin(pageName) {
  89. this.loadUser() // 每次点击都刷新登录状态
  90. if (!this.token) {
  91. // 未登录 → 弹窗
  92. this.dialogToggle()
  93. return
  94. }
  95. // 已登录 → 这里写正常跳转
  96. // uni.showToast({
  97. // title: `进入【${pageName}】`,
  98. // icon: "none"
  99. // })
  100. // 真实跳转示例:
  101. // uni.navigateTo({
  102. // url: `/pages/${pageName}/${pageName}`
  103. // })
  104. if(pageName==='借阅'){
  105. uni.navigateTo({
  106. url: '/subpkg/pages/myLending/myLending'
  107. });
  108. }else if(pageName==='我的留言'){
  109. uni.navigateTo({
  110. url: '/subpkg/pages/feedback-list/feedback-list'
  111. });
  112. }else if(pageName==='修改密码'){
  113. uni.navigateTo({
  114. url: '/subpkg/pages/change-password/change-password'
  115. });
  116. }else if(pageName==='收藏'){
  117. uni.navigateTo({
  118. url: '/subpkg/pages/collect-list/collect-list'
  119. });
  120. }else if(pageName==='个人资料'){
  121. uni.navigateTo({
  122. url: '/subpkg/pages/user-info/user-info'
  123. });
  124. }
  125. },
  126. // 弹出绑定提示
  127. dialogToggle() {
  128. this.$refs.alertDialog.open();
  129. },
  130. // 绑定读者证 → 获取微信信息 → 跳登录页
  131. dialogConfirm() {
  132. uni.getUserProfile({
  133. desc: "绑定读者证",
  134. success: (res) => {
  135. const userInfo = JSON.parse(res.rawData);
  136. uni.setStorageSync("wxUserInfo", userInfo);
  137. uni.setStorageSync("wxSignature", res.signature);
  138. // 跳转到登录页
  139. uni.navigateTo({
  140. url: "/pages/login/login"
  141. });
  142. },
  143. fail: () => {
  144. uni.showToast({ title: "授权失败", icon: "error" });
  145. }
  146. });
  147. },
  148. dialogClose() {
  149. console.log('取消')
  150. },
  151. toLogOut() {
  152. // 弹窗确认退出
  153. uni.showModal({
  154. title: '确认退出',
  155. content: '确定要退出当前账号吗?',
  156. success: (res) => {
  157. if (res.confirm) {
  158. // 1. 清空所有登录相关缓存
  159. uni.removeStorageSync("token");
  160. uni.removeStorageSync("user-info");
  161. uni.removeStorageSync("wxUserInfo");
  162. uni.removeStorageSync("wxSignature");
  163. // 2. 重置当前页面的登录状态(你的首页变量)
  164. this.token = "";
  165. this.userInfo = {};
  166. this.isBindLibraryCard = false;
  167. // 3. 提示
  168. uni.showToast({
  169. title: '退出成功',
  170. icon: 'success'
  171. });
  172. // 跳回首页
  173. uni.switchTab({
  174. url: "/pages/home/home"
  175. });
  176. // 跳转到登录页
  177. // uni.navigateTo({
  178. // url: "/pages/login/login"
  179. // });
  180. }
  181. }
  182. });
  183. },
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. .top-user-bar{
  189. position: relative;
  190. width: 100%;
  191. height: 150px;
  192. display: flex;
  193. align-items: center;
  194. color: $uni-white;
  195. .top-bar-bg{
  196. position: absolute;
  197. left: 0;
  198. top: 0;
  199. display: block;
  200. width: 100%;
  201. height: 100%;
  202. z-index: 1;
  203. }
  204. .user-info{
  205. position: absolute;
  206. left: 0;
  207. top: 0;
  208. z-index: 99;
  209. display: flex;
  210. justify-content: flex-start;
  211. .avatar{
  212. width: 62px;
  213. height: 62px;
  214. border-radius: 31px;
  215. margin-top: 19px;
  216. margin-left: 28px;
  217. }
  218. .user-info-text{
  219. display: flex;
  220. flex-direction: column;
  221. align-items: flex-start;
  222. justify-content: flex-start;
  223. margin: 26px 16px 0 16px;
  224. .user-name{
  225. font-size: 20px;
  226. font-weight: 500;
  227. color: #fff;
  228. line-height: 28px;
  229. }
  230. .user-card{
  231. margin-top: 5px;
  232. font-size: 12px;
  233. font-weight: 400;
  234. color: #fff;
  235. line-height: 17px;
  236. }
  237. }
  238. }
  239. .user-menu{
  240. position: absolute;
  241. bottom: -60px;
  242. left: 0;
  243. background-color: #fff;
  244. z-index: 99;
  245. display: flex;
  246. justify-content: flex-start;
  247. width: calc(100% - 40px);
  248. margin: 0 20px;
  249. border-radius: 6px;
  250. box-shadow: 0px 2px 15px 0px rgba(0, 0, 0, .1);
  251. .menu-item{
  252. display: flex;
  253. flex-direction: column;
  254. align-items: center;
  255. justify-content: center;
  256. padding: 0 30px;
  257. height: 100px;
  258. .menu-icon{
  259. width: 32px;
  260. height: 32px;
  261. margin-bottom: 10px;
  262. }
  263. .menu-txt{
  264. color: #636365;
  265. font-size: 13px;
  266. }
  267. }
  268. }
  269. }
  270. .submenu-box{
  271. margin-top: 80px;
  272. background-color: #fff;
  273. display: flex;
  274. flex-direction: column;
  275. align-items: center;
  276. justify-content: center;
  277. .submenu-item{
  278. display: flex;
  279. align-items: center;
  280. justify-content: flex-start;
  281. width: calc(100% - 40px);
  282. background-color: #fff;
  283. border-bottom: 1px solid #f4f4f4;
  284. height: 45px;
  285. padding: 0 20px;
  286. ::v-deep .uni-icons{
  287. color: #343434 !important;
  288. }
  289. .left-txt{
  290. color: #343434;
  291. font-size: 14px;
  292. width: calc(100% - 50px);
  293. white-space: nowrap;
  294. overflow: hidden;
  295. text-overflow: ellipsis;
  296. margin-left: 10px;
  297. }
  298. }
  299. }
  300. </style>