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

342 lines
8.6 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
1 month ago
2 months ago
1 month 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
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. <uni-popup ref="alertDialog" type="dialog">
  42. <uni-popup-dialog
  43. type="info" cancelText="取消" confirmText="确定"
  44. title="提示" content="请您绑定读者证!"
  45. @confirm="dialogConfirm" @close="dialogClose">
  46. </uni-popup-dialog>
  47. </uni-popup>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import config from '@/utils/config';
  53. import { FetchFindAllReaderByOpenId } from '@/api/user';
  54. import { getReaderCardList, STORAGE_KEYS } from '@/utils/storage';
  55. const USER_KEY = 'user-info';
  56. export default {
  57. data() {
  58. return {
  59. userInfo: {},
  60. cardNo: "",
  61. isBindLibraryCard: false,
  62. base64Img: "",
  63. loading: false,
  64. };
  65. },
  66. onLoad() {
  67. this.loadUserInfo();
  68. },
  69. onShow() {
  70. this.loadUserInfo();
  71. },
  72. methods:{
  73. toUserInfoPage() {
  74. uni.navigateTo({
  75. url: '/subpkg/pages/user-info/user-info'
  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: '1201',
  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. this.dialogToggle();
  128. return;
  129. }
  130. const routeMap = {
  131. '收藏': '/subpkg/pages/collect-list/collect-list',
  132. '借阅': () => {
  133. uni.setStorageSync('switch_tab_index', 0);
  134. uni.navigateTo({
  135. url: '/subpkg/pages/myLending/myLending'
  136. });
  137. },
  138. '我的留言': '/subpkg/pages/feedback-list/feedback-list',
  139. '解绑读者证': '/subpkg/pages/reader-card/reader-card'
  140. };
  141. const target = routeMap[pageName];
  142. if (typeof target === 'function') {
  143. target();
  144. } else if (target) {
  145. uni.navigateTo({ url: target });
  146. }
  147. },
  148. dialogToggle() {
  149. this.$refs.alertDialog.open();
  150. },
  151. dialogConfirm() {
  152. uni.navigateTo({ url: "/pages/login/login" });
  153. },
  154. dialogClose() {},
  155. urlToBase64(url) {
  156. return new Promise((resolve, reject) => {
  157. uni.request({
  158. url,
  159. method: 'GET',
  160. responseType: 'arraybuffer',
  161. success: (res) => {
  162. try {
  163. const base64 = uni.arrayBufferToBase64(res.data);
  164. const dataUri = 'data:image/jpeg;base64,' + base64;
  165. resolve(dataUri);
  166. } catch (e) {
  167. reject(e);
  168. }
  169. },
  170. fail: (err) => {
  171. console.error('[User] Failed to fetch image:', err);
  172. reject(err);
  173. }
  174. });
  175. });
  176. },
  177. toLogOut() {
  178. uni.showModal({
  179. title: '确认退出',
  180. content: '确定要退出当前账号吗?',
  181. success: (res) => {
  182. if (res.confirm) {
  183. uni.removeStorageSync(USER_KEY);
  184. uni.removeStorageSync(STORAGE_KEYS.READER_CARD_LIST);
  185. uni.removeStorageSync(STORAGE_KEYS.CURRENT_READER_CARD);
  186. this.userInfo = {};
  187. this.cardNo = "";
  188. this.isBindLibraryCard = false;
  189. this.base64Img = "";
  190. uni.showToast({ title: '退出成功', icon: 'success' });
  191. uni.switchTab({ url: "/pages/home/home" });
  192. }
  193. }
  194. });
  195. },
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .top-user-bar{
  201. position: relative;
  202. width: 100%;
  203. height: 150px;
  204. display: flex;
  205. align-items: center;
  206. color: $uni-white;
  207. .top-bar-bg{
  208. position: absolute;
  209. left: 0;
  210. top: 0;
  211. display: block;
  212. width: 100%;
  213. height: 100%;
  214. z-index: 1;
  215. }
  216. .user-info{
  217. position: absolute;
  218. left: 0;
  219. top: 0;
  220. z-index: 99;
  221. display: flex;
  222. justify-content: flex-start;
  223. .avatar-btn {
  224. background: transparent;
  225. margin-top: 19px;
  226. margin-left: 28px;
  227. &::after{ border: none !important; }
  228. .avatar-img {
  229. width: 62px;
  230. height: 62px;
  231. border-radius: 50%;
  232. object-fit: cover;
  233. }
  234. }
  235. .user-info-text{
  236. display: flex;
  237. flex-direction: column;
  238. align-items: flex-start;
  239. justify-content: flex-start;
  240. margin: 26px 16px 0 16px;
  241. .user-name{
  242. font-size: 20px;
  243. font-weight: 500;
  244. color: #fff;
  245. line-height: 28px;
  246. }
  247. .user-card{
  248. margin-top: 5px;
  249. font-size: 13px;
  250. color: #fff;
  251. line-height: 17px;
  252. }
  253. }
  254. }
  255. .user-menu{
  256. position: absolute;
  257. bottom: -60px;
  258. left: 0;
  259. background-color: #fff;
  260. z-index: 99;
  261. display: flex;
  262. justify-content: flex-start;
  263. width: calc(100% - 40px);
  264. margin: 0 20px;
  265. border-radius: 6px;
  266. box-shadow: 0px 2px 15px 0px rgba(0, 0, 0, .1);
  267. .menu-item{
  268. display: flex;
  269. flex-direction: column;
  270. align-items: center;
  271. justify-content: center;
  272. padding: 0 30px;
  273. height: 100px;
  274. .menu-icon{
  275. width: 32px;
  276. height: 32px;
  277. margin-bottom: 10px;
  278. }
  279. .menu-txt{
  280. color: #636365;
  281. font-size: 13px;
  282. }
  283. }
  284. }
  285. }
  286. .submenu-box{
  287. margin-top: 80px;
  288. background-color: #fff;
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. justify-content: center;
  293. .submenu-item{
  294. display: flex;
  295. align-items: center;
  296. justify-content: flex-start;
  297. width: calc(100% - 40px);
  298. background-color: #fff;
  299. border-bottom: 1px solid #f4f4f4;
  300. height: 45px;
  301. padding: 0 20px;
  302. ::v-deep .uni-icons{
  303. color: #343434 !important;
  304. }
  305. .left-txt{
  306. color: #343434;
  307. font-size: 14px;
  308. width: calc(100% - 50px);
  309. white-space: nowrap;
  310. overflow: hidden;
  311. text-overflow: ellipsis;
  312. margin-left: 10px;
  313. }
  314. }
  315. }
  316. </style>