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

320 lines
8.1 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
4 weeks 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
1 month ago
2 months 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 class="menu-item" @click="toBookingRecord">
  25. <image class="menu-icon" src="@/static/images/menu-rg.png" mode="scaleToFill" style="width: 30px; height: 30px; margin-bottom: 8px;" />
  26. <text class="menu-txt">入馆</text>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="submenu-box">
  31. <view class="submenu-item" @click="toCheckLogin('我的留言')">
  32. <uni-icons custom-prefix="iconfont" type="icon-liuyan" size="20"></uni-icons>
  33. <text class="left-txt">我的留言</text>
  34. </view>
  35. <view class="submenu-item" @click="toUserInfoPage">
  36. <uni-icons custom-prefix="iconfont" type="icon-shezhi" size="20"></uni-icons>
  37. <text class="left-txt">个人资料</text>
  38. </view>
  39. <view class="submenu-item" @click="toCheckLogin('解绑读者证')">
  40. <uni-icons custom-prefix="iconfont" type="icon-UIsheji_menjinxitong-28" size="20"></uni-icons>
  41. <text class="left-txt">解绑读者证</text>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import config from '@/utils/config';
  48. import { FetchFindAllReaderByOpenId } from '@/api/user';
  49. import { getReaderCardList, STORAGE_KEYS } from '@/utils/storage';
  50. const USER_KEY = 'user-info';
  51. export default {
  52. data() {
  53. return {
  54. userInfo: {},
  55. cardNo: "",
  56. isBindLibraryCard: false,
  57. base64Img: "",
  58. loading: false,
  59. };
  60. },
  61. onLoad() {
  62. this.loadUserInfo();
  63. },
  64. onShow() {
  65. this.loadUserInfo();
  66. },
  67. methods:{
  68. toUserInfoPage() {
  69. uni.navigateTo({
  70. url: '/subpkg/pages/user-info/user-info'
  71. });
  72. },
  73. toBookingRecord() {
  74. uni.navigateTo({
  75. url: '/subpkg/pages/booking-record/booking-record'
  76. });
  77. },
  78. async loadUserInfo() {
  79. if (this.loading) return;
  80. this.loading = true;
  81. try {
  82. const readerList = await getReaderCardList();
  83. const openId = uni.getStorageSync(STORAGE_KEYS.WX_LOGIN_CODE);
  84. if (openId) {
  85. const res = await FetchFindAllReaderByOpenId({
  86. libcode: config.LIB_CODE,
  87. openId: openId
  88. });
  89. if (res.code === 200 && res.data) {
  90. this.userInfo = {
  91. nickname: res.data.nickname || '',
  92. avatarId: res.data.avatar || ''
  93. };
  94. if (res.data.avatar) {
  95. const imageUrl = config.baseUrl + '/api/fileRelevant/getImg?imgType=5&imgId=' + res.data.avatar;
  96. try {
  97. const base64 = await this.urlToBase64(imageUrl);
  98. this.base64Img = base64;
  99. } catch (err) {
  100. console.error('[User] Failed to load avatar:', err);
  101. }
  102. }
  103. uni.setStorageSync(USER_KEY, this.userInfo);
  104. } else {
  105. this.userInfo = uni.getStorageSync(USER_KEY) || {};
  106. }
  107. } else {
  108. this.userInfo = uni.getStorageSync(USER_KEY) || {};
  109. }
  110. const defaultCard = readerList.find(item => item.bindDefault === true);
  111. this.cardNo = defaultCard ? defaultCard.bindValue : (readerList[0]?.bindValue || '');
  112. this.isBindLibraryCard = readerList.length > 0;
  113. } catch (err) {
  114. console.error('[User] Failed to load user info:', err);
  115. const readerList = uni.getStorageSync(STORAGE_KEYS.READER_CARD_LIST) || [];
  116. this.userInfo = uni.getStorageSync(USER_KEY) || {};
  117. const defaultCard = readerList.find(item => item.bindDefault === true);
  118. this.cardNo = defaultCard ? defaultCard.bindValue : (readerList[0]?.bindValue || '');
  119. this.isBindLibraryCard = readerList.length > 0;
  120. } finally {
  121. this.loading = false;
  122. }
  123. },
  124. async toCheckLogin(pageName) {
  125. const readerList = await getReaderCardList();
  126. if (readerList.length === 0) {
  127. uni.showModal({
  128. title: '提示',
  129. content: '请您绑定读者证',
  130. confirmText: '去绑定',
  131. cancelText: '取消',
  132. success: (res) => {
  133. if (res.confirm) {
  134. uni.navigateTo({ url: "/pages/login/login" });
  135. }
  136. }
  137. });
  138. return;
  139. }
  140. const routeMap = {
  141. '收藏': '/subpkg/pages/collect-list/collect-list',
  142. '借阅': () => {
  143. uni.setStorageSync('switch_tab_index', 0);
  144. uni.navigateTo({
  145. url: '/subpkg/pages/myLending/myLending'
  146. });
  147. },
  148. '我的留言': '/subpkg/pages/feedback-list/feedback-list',
  149. '解绑读者证': '/subpkg/pages/reader-card/reader-card'
  150. };
  151. const target = routeMap[pageName];
  152. if (typeof target === 'function') {
  153. target();
  154. } else if (target) {
  155. uni.navigateTo({ url: target });
  156. }
  157. },
  158. urlToBase64(url) {
  159. return new Promise((resolve, reject) => {
  160. uni.request({
  161. url,
  162. method: 'GET',
  163. responseType: 'arraybuffer',
  164. success: (res) => {
  165. try {
  166. const base64 = uni.arrayBufferToBase64(res.data);
  167. const dataUri = 'data:image/jpeg;base64,' + base64;
  168. resolve(dataUri);
  169. } catch (e) {
  170. reject(e);
  171. }
  172. },
  173. fail: (err) => {
  174. console.error('[User] Failed to fetch image:', err);
  175. reject(err);
  176. }
  177. });
  178. });
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. .top-user-bar{
  185. position: relative;
  186. width: 100%;
  187. height: 150px;
  188. display: flex;
  189. align-items: center;
  190. color: $uni-white;
  191. .top-bar-bg{
  192. position: absolute;
  193. left: 0;
  194. top: 0;
  195. display: block;
  196. width: 100%;
  197. height: 100%;
  198. z-index: 1;
  199. }
  200. .user-info{
  201. position: absolute;
  202. left: 0;
  203. top: 0;
  204. z-index: 99;
  205. display: flex;
  206. justify-content: flex-start;
  207. .avatar-btn {
  208. background: transparent;
  209. margin-top: 19px;
  210. margin-left: 28px;
  211. &::after{ border: none !important; }
  212. .avatar-img {
  213. width: 62px;
  214. height: 62px;
  215. border-radius: 50%;
  216. object-fit: cover;
  217. }
  218. }
  219. .user-info-text{
  220. display: flex;
  221. flex-direction: column;
  222. align-items: flex-start;
  223. justify-content: flex-start;
  224. margin: 26px 16px 0 16px;
  225. .user-name{
  226. font-size: 20px;
  227. font-weight: 500;
  228. color: #fff;
  229. line-height: 28px;
  230. }
  231. .user-card{
  232. margin-top: 5px;
  233. font-size: 13px;
  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>