图书馆小程序
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.

332 lines
8.4 KiB

2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
2 months ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months 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. <view class="avatar-btn" @click="toUserInfoPage">
  7. <image v-if="userInfo.avatarId" :src="base64Img" class="avatar-img"></image>
  8. <image v-else src="@/static/images/logo.jpg" class="avatar-img"></image>
  9. </view>
  10. <view class="user-info-text">
  11. <text class="user-name" @click="toUserInfoPage">{{ userInfo.nickname || '未设置' }}</text>
  12. <text class="user-card" v-if="cardNo">读者证{{ cardNo }}</text>
  13. </view>
  14. </view>
  15. <view class="user-menu">
  16. <view class="menu-item" @click="toCheckLogin('收藏')">
  17. <image class="menu-icon" src="@/static/images/menu-sc.png" mode="scaleToFill" />
  18. <text class="menu-txt">收藏</text>
  19. </view>
  20. <view class="menu-item" @click="toCheckLogin('借阅')">
  21. <image class="menu-icon" src="@/static/images/menu-jy.png" mode="scaleToFill" />
  22. <text class="menu-txt">借阅</text>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="submenu-box">
  27. <view class="submenu-item" @click="toCheckLogin('我的留言')">
  28. <uni-icons custom-prefix="iconfont" type="icon-liuyan" size="20"></uni-icons>
  29. <text class="left-txt">我的留言</text>
  30. </view>
  31. <view class="submenu-item" @click="toUserInfoPage">
  32. <uni-icons custom-prefix="iconfont" type="icon-shezhi" size="20"></uni-icons>
  33. <text class="left-txt">个人资料</text>
  34. </view>
  35. <view class="submenu-item" @click="toCheckLogin('解绑读者证')">
  36. <uni-icons custom-prefix="iconfont" type="icon-UIsheji_menjinxitong-28" size="20"></uni-icons>
  37. <text class="left-txt">解绑读者证</text>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import config from '@/utils/config';
  44. import { FetchFindAllReaderByOpenId } from '@/api/user';
  45. import { getReaderCardList, STORAGE_KEYS } from '@/utils/storage';
  46. const USER_KEY = 'user-info';
  47. export default {
  48. data() {
  49. return {
  50. userInfo: {},
  51. cardNo: "",
  52. isBindLibraryCard: false,
  53. base64Img: "",
  54. loading: false,
  55. };
  56. },
  57. onLoad() {
  58. this.loadUserInfo();
  59. },
  60. onShow() {
  61. this.loadUserInfo();
  62. },
  63. methods:{
  64. toUserInfoPage() {
  65. uni.navigateTo({
  66. url: '/subpkg/pages/user-info/user-info'
  67. });
  68. },
  69. async loadUserInfo() {
  70. if (this.loading) return;
  71. this.loading = true;
  72. try {
  73. const readerList = await getReaderCardList();
  74. const openId = uni.getStorageSync(STORAGE_KEYS.WX_LOGIN_CODE);
  75. if (openId) {
  76. const res = await FetchFindAllReaderByOpenId({
  77. libcode: '1201',
  78. openId: openId
  79. });
  80. if (res.code === 200 && res.data) {
  81. this.userInfo = {
  82. nickname: res.data.nickname || '',
  83. avatarId: res.data.avatar || ''
  84. };
  85. if (res.data.avatar) {
  86. const imageUrl = config.baseUrl + '/api/fileRelevant/getImg?imgType=5&imgId=' + res.data.avatar;
  87. try {
  88. const base64 = await this.urlToBase64(imageUrl);
  89. this.base64Img = base64;
  90. } catch (err) {
  91. console.error('[User] Failed to load avatar:', err);
  92. }
  93. }
  94. uni.setStorageSync(USER_KEY, this.userInfo);
  95. } else {
  96. this.userInfo = uni.getStorageSync(USER_KEY) || {};
  97. }
  98. } else {
  99. this.userInfo = uni.getStorageSync(USER_KEY) || {};
  100. }
  101. const defaultCard = readerList.find(item => item.bindDefault === true);
  102. this.cardNo = defaultCard ? defaultCard.bindValue : (readerList[0]?.bindValue || '');
  103. this.isBindLibraryCard = readerList.length > 0;
  104. } catch (err) {
  105. console.error('[User] Failed to load user info:', err);
  106. const readerList = uni.getStorageSync(STORAGE_KEYS.READER_CARD_LIST) || [];
  107. this.userInfo = uni.getStorageSync(USER_KEY) || {};
  108. const defaultCard = readerList.find(item => item.bindDefault === true);
  109. this.cardNo = defaultCard ? defaultCard.bindValue : (readerList[0]?.bindValue || '');
  110. this.isBindLibraryCard = readerList.length > 0;
  111. } finally {
  112. this.loading = false;
  113. }
  114. },
  115. async toCheckLogin(pageName) {
  116. const readerList = await getReaderCardList();
  117. if (readerList.length === 0) {
  118. uni.showModal({
  119. title: '提示',
  120. content: '请您绑定读者证',
  121. confirmText: '去绑定',
  122. cancelText: '取消',
  123. success: (res) => {
  124. if (res.confirm) {
  125. uni.navigateTo({ url: "/pages/login/login" });
  126. }
  127. }
  128. });
  129. return;
  130. }
  131. const routeMap = {
  132. '收藏': '/subpkg/pages/collect-list/collect-list',
  133. '借阅': () => {
  134. uni.setStorageSync('switch_tab_index', 0);
  135. uni.navigateTo({
  136. url: '/subpkg/pages/myLending/myLending'
  137. });
  138. },
  139. '我的留言': '/subpkg/pages/feedback-list/feedback-list',
  140. '解绑读者证': '/subpkg/pages/reader-card/reader-card'
  141. };
  142. const target = routeMap[pageName];
  143. if (typeof target === 'function') {
  144. target();
  145. } else if (target) {
  146. uni.navigateTo({ url: target });
  147. }
  148. },
  149. urlToBase64(url) {
  150. return new Promise((resolve, reject) => {
  151. uni.request({
  152. url,
  153. method: 'GET',
  154. responseType: 'arraybuffer',
  155. success: (res) => {
  156. try {
  157. const base64 = uni.arrayBufferToBase64(res.data);
  158. const dataUri = 'data:image/jpeg;base64,' + base64;
  159. resolve(dataUri);
  160. } catch (e) {
  161. reject(e);
  162. }
  163. },
  164. fail: (err) => {
  165. console.error('[User] Failed to fetch image:', err);
  166. reject(err);
  167. }
  168. });
  169. });
  170. },
  171. toLogOut() {
  172. uni.showModal({
  173. title: '确认退出',
  174. content: '确定要退出当前账号吗?',
  175. success: (res) => {
  176. if (res.confirm) {
  177. uni.removeStorageSync(USER_KEY);
  178. uni.removeStorageSync(STORAGE_KEYS.READER_CARD_LIST);
  179. uni.removeStorageSync(STORAGE_KEYS.CURRENT_READER_CARD);
  180. this.userInfo = {};
  181. this.cardNo = "";
  182. this.isBindLibraryCard = false;
  183. this.base64Img = "";
  184. uni.showToast({ title: '退出成功', icon: 'success' });
  185. uni.switchTab({ url: "/pages/home/home" });
  186. }
  187. }
  188. });
  189. },
  190. }
  191. }
  192. </script>
  193. <style lang="scss" scoped>
  194. .top-user-bar{
  195. position: relative;
  196. width: 100%;
  197. height: 150px;
  198. display: flex;
  199. align-items: center;
  200. color: $uni-white;
  201. .top-bar-bg{
  202. position: absolute;
  203. left: 0;
  204. top: 0;
  205. display: block;
  206. width: 100%;
  207. height: 100%;
  208. z-index: 1;
  209. }
  210. .user-info{
  211. position: absolute;
  212. left: 0;
  213. top: 0;
  214. z-index: 99;
  215. display: flex;
  216. justify-content: flex-start;
  217. .avatar-btn {
  218. background: transparent;
  219. margin-top: 19px;
  220. margin-left: 28px;
  221. &::after{ border: none !important; }
  222. .avatar-img {
  223. width: 62px;
  224. height: 62px;
  225. border-radius: 50%;
  226. object-fit: cover;
  227. }
  228. }
  229. .user-info-text{
  230. display: flex;
  231. flex-direction: column;
  232. align-items: flex-start;
  233. justify-content: flex-start;
  234. margin: 26px 16px 0 16px;
  235. .user-name{
  236. font-size: 20px;
  237. font-weight: 500;
  238. color: #fff;
  239. line-height: 28px;
  240. }
  241. .user-card{
  242. margin-top: 5px;
  243. font-size: 13px;
  244. color: #fff;
  245. line-height: 17px;
  246. }
  247. }
  248. }
  249. .user-menu{
  250. position: absolute;
  251. bottom: -60px;
  252. left: 0;
  253. background-color: #fff;
  254. z-index: 99;
  255. display: flex;
  256. justify-content: flex-start;
  257. width: calc(100% - 40px);
  258. margin: 0 20px;
  259. border-radius: 6px;
  260. box-shadow: 0px 2px 15px 0px rgba(0, 0, 0, .1);
  261. .menu-item{
  262. display: flex;
  263. flex-direction: column;
  264. align-items: center;
  265. justify-content: center;
  266. padding: 0 30px;
  267. height: 100px;
  268. .menu-icon{
  269. width: 32px;
  270. height: 32px;
  271. margin-bottom: 10px;
  272. }
  273. .menu-txt{
  274. color: #636365;
  275. font-size: 13px;
  276. }
  277. }
  278. }
  279. }
  280. .submenu-box{
  281. margin-top: 80px;
  282. background-color: #fff;
  283. display: flex;
  284. flex-direction: column;
  285. align-items: center;
  286. justify-content: center;
  287. .submenu-item{
  288. display: flex;
  289. align-items: center;
  290. justify-content: flex-start;
  291. width: calc(100% - 40px);
  292. background-color: #fff;
  293. border-bottom: 1px solid #f4f4f4;
  294. height: 45px;
  295. padding: 0 20px;
  296. ::v-deep .uni-icons{
  297. color: #343434 !important;
  298. }
  299. .left-txt{
  300. color: #343434;
  301. font-size: 14px;
  302. width: calc(100% - 50px);
  303. white-space: nowrap;
  304. overflow: hidden;
  305. text-overflow: ellipsis;
  306. margin-left: 10px;
  307. }
  308. }
  309. }
  310. </style>