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

327 lines
8.5 KiB

5 months 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
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 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/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 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: config.LIB_CODE,
  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. try {
  106. const base64 = await this.urlToBase64(imageUrl);
  107. this.base64Img = base64;
  108. } catch (err) {
  109. console.error('[User] Failed to load avatar:', err);
  110. }
  111. }
  112. uni.setStorageSync(USER_KEY, this.userInfo);
  113. } else {
  114. this.userInfo = uni.getStorageSync(USER_KEY) || {};
  115. }
  116. } else {
  117. this.userInfo = uni.getStorageSync(USER_KEY) || {};
  118. }
  119. const defaultCard = readerList.find(item => item.bindDefault === true);
  120. this.cardNo = defaultCard ? defaultCard.bindValue : (readerList[0]?.bindValue || '');
  121. this.isBindLibraryCard = readerList.length > 0;
  122. } catch (err) {
  123. console.error('[User] Failed to load user info:', err);
  124. const readerList = uni.getStorageSync(STORAGE_KEYS.READER_CARD_LIST) || [];
  125. this.userInfo = uni.getStorageSync(USER_KEY) || {};
  126. const defaultCard = readerList.find(item => item.bindDefault === true);
  127. this.cardNo = defaultCard ? defaultCard.bindValue : (readerList[0]?.bindValue || '');
  128. this.isBindLibraryCard = readerList.length > 0;
  129. } finally {
  130. this.loading = false;
  131. }
  132. },
  133. async toCheckLogin(pageName) {
  134. const readerList = await getReaderCardList();
  135. if (readerList.length === 0) {
  136. uni.showModal({
  137. title: '提示',
  138. content: '请您绑定读者证',
  139. confirmText: '去绑定',
  140. cancelText: '取消',
  141. success: (res) => {
  142. if (res.confirm) {
  143. uni.navigateTo({ url: "/pages/login/login" });
  144. }
  145. }
  146. });
  147. return;
  148. }
  149. const routeMap = {
  150. '收藏': '/subpkg/pages/collect-list/collect-list',
  151. '借阅': () => {
  152. uni.setStorageSync('switch_tab_index', 0);
  153. uni.navigateTo({
  154. url: '/subpkg/pages/myLending/myLending'
  155. });
  156. },
  157. '我的留言': '/subpkg/pages/feedback-list/feedback-list',
  158. '解绑读者证': '/subpkg/pages/reader-card/reader-card'
  159. };
  160. const target = routeMap[pageName];
  161. if (typeof target === 'function') {
  162. target();
  163. } else if (target) {
  164. uni.navigateTo({ url: target });
  165. }
  166. },
  167. urlToBase64(url) {
  168. return new Promise((resolve, reject) => {
  169. uni.request({
  170. url,
  171. method: 'GET',
  172. responseType: 'arraybuffer',
  173. success: (res) => {
  174. try {
  175. const base64 = uni.arrayBufferToBase64(res.data);
  176. const dataUri = 'data:image/jpeg;base64,' + base64;
  177. resolve(dataUri);
  178. } catch (e) {
  179. reject(e);
  180. }
  181. },
  182. fail: (err) => {
  183. console.error('[User] Failed to fetch image:', err);
  184. reject(err);
  185. }
  186. });
  187. });
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. .top-user-bar{
  194. position: relative;
  195. width: 100%;
  196. height: 150px;
  197. display: flex;
  198. align-items: center;
  199. color: $uni-white;
  200. .top-bar-bg{
  201. position: absolute;
  202. left: 0;
  203. top: 0;
  204. display: block;
  205. width: 100%;
  206. height: 100%;
  207. z-index: 1;
  208. }
  209. .user-info{
  210. position: absolute;
  211. left: 0;
  212. top: 0;
  213. z-index: 99;
  214. display: flex;
  215. justify-content: flex-start;
  216. .avatar-btn {
  217. background: transparent;
  218. margin-top: 19px;
  219. margin-left: 28px;
  220. &::after{ border: none !important; }
  221. .avatar-img {
  222. width: 62px;
  223. height: 62px;
  224. border-radius: 50%;
  225. object-fit: cover;
  226. }
  227. }
  228. .user-info-text{
  229. display: flex;
  230. flex-direction: column;
  231. align-items: flex-start;
  232. justify-content: flex-start;
  233. margin: 26px 16px 0 16px;
  234. .user-name{
  235. font-size: 20px;
  236. font-weight: 500;
  237. color: #fff;
  238. line-height: 28px;
  239. }
  240. .user-card{
  241. margin-top: 5px;
  242. font-size: 13px;
  243. color: #fff;
  244. line-height: 17px;
  245. }
  246. }
  247. }
  248. .user-menu{
  249. position: absolute;
  250. bottom: -60px;
  251. left: 0;
  252. background-color: #fff;
  253. z-index: 99;
  254. display: flex;
  255. justify-content: flex-start;
  256. width: calc(100% - 40px);
  257. margin: 0 20px;
  258. border-radius: 6px;
  259. box-shadow: 0px 2px 15px 0px rgba(0, 0, 0, .1);
  260. .menu-item{
  261. width: 25%;
  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>