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

310 lines
7.8 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
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. }
  172. }
  173. </script>
  174. <style lang="scss" scoped>
  175. .top-user-bar{
  176. position: relative;
  177. width: 100%;
  178. height: 150px;
  179. display: flex;
  180. align-items: center;
  181. color: $uni-white;
  182. .top-bar-bg{
  183. position: absolute;
  184. left: 0;
  185. top: 0;
  186. display: block;
  187. width: 100%;
  188. height: 100%;
  189. z-index: 1;
  190. }
  191. .user-info{
  192. position: absolute;
  193. left: 0;
  194. top: 0;
  195. z-index: 99;
  196. display: flex;
  197. justify-content: flex-start;
  198. .avatar-btn {
  199. background: transparent;
  200. margin-top: 19px;
  201. margin-left: 28px;
  202. &::after{ border: none !important; }
  203. .avatar-img {
  204. width: 62px;
  205. height: 62px;
  206. border-radius: 50%;
  207. object-fit: cover;
  208. }
  209. }
  210. .user-info-text{
  211. display: flex;
  212. flex-direction: column;
  213. align-items: flex-start;
  214. justify-content: flex-start;
  215. margin: 26px 16px 0 16px;
  216. .user-name{
  217. font-size: 20px;
  218. font-weight: 500;
  219. color: #fff;
  220. line-height: 28px;
  221. }
  222. .user-card{
  223. margin-top: 5px;
  224. font-size: 13px;
  225. color: #fff;
  226. line-height: 17px;
  227. }
  228. }
  229. }
  230. .user-menu{
  231. position: absolute;
  232. bottom: -60px;
  233. left: 0;
  234. background-color: #fff;
  235. z-index: 99;
  236. display: flex;
  237. justify-content: flex-start;
  238. width: calc(100% - 40px);
  239. margin: 0 20px;
  240. border-radius: 6px;
  241. box-shadow: 0px 2px 15px 0px rgba(0, 0, 0, .1);
  242. .menu-item{
  243. display: flex;
  244. flex-direction: column;
  245. align-items: center;
  246. justify-content: center;
  247. padding: 0 30px;
  248. height: 100px;
  249. .menu-icon{
  250. width: 32px;
  251. height: 32px;
  252. margin-bottom: 10px;
  253. }
  254. .menu-txt{
  255. color: #636365;
  256. font-size: 13px;
  257. }
  258. }
  259. }
  260. }
  261. .submenu-box{
  262. margin-top: 80px;
  263. background-color: #fff;
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. justify-content: center;
  268. .submenu-item{
  269. display: flex;
  270. align-items: center;
  271. justify-content: flex-start;
  272. width: calc(100% - 40px);
  273. background-color: #fff;
  274. border-bottom: 1px solid #f4f4f4;
  275. height: 45px;
  276. padding: 0 20px;
  277. ::v-deep .uni-icons{
  278. color: #343434 !important;
  279. }
  280. .left-txt{
  281. color: #343434;
  282. font-size: 14px;
  283. width: calc(100% - 50px);
  284. white-space: nowrap;
  285. overflow: hidden;
  286. text-overflow: ellipsis;
  287. margin-left: 10px;
  288. }
  289. }
  290. }
  291. </style>