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

329 lines
8.7 KiB

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