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

380 lines
9.9 KiB

6 months ago
​
​
6 months ago
​
​
​
​
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
​
​
​
​
​
6 months ago
​
6 months ago
6 months ago
​
​
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
​
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
​
​
​
6 months ago
​
​
​
​
​
6 months ago
​
​
​
​
6 months ago
6 months ago
​
6 months ago
6 months ago
​
​
​
​
​
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
​
​
​
​
​
​
6 months ago
​
​
6 months ago
6 months ago
6 months ago
​
​
​
6 months ago
​
​
​
​
​
​
6 months ago
6 months ago
6 months ago
​
6 months ago
6 months ago
​
6 months ago
6 months ago
6 months ago
​
​
6 months ago
6 months ago
6 months ago
6 months ago
​
6 months ago
6 months ago
​
6 months ago
6 months ago
6 months ago
​
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
​
​
​
​
6 months ago
​
​
6 months ago
6 months ago
6 months ago
​
​
​
​
6 months ago
​
​
​
​
​
​
​
​
​
​
​
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
​
​
​
6 months ago
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
​
​
​
​
​
​
​
6 months ago
​
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
6 months ago
​
​
​
​
6 months ago
6 months ago
6 months ago
6 months ago
​
​
​
6 months ago
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
​
6 months ago
​
​
6 months ago
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
  1. <template>
  2. <view class="reader-card">
  3. <image class="card-top-bg" src="@/static/images/card-img1.png" mode="widthFix" />
  4. <view class="edit-btn" @click="toggleEditMode">
  5. {{ isEditMode ? '完成' : '解绑' }}
  6. </view>
  7. <view class="card-list">
  8. <view
  9. class="card-list-item"
  10. v-for="(item, index) in cardList"
  11. :key="item.id"
  12. @click="handleSelectItem(item.bindValue)"
  13. :class="{ active: selectedValue === item.bindValue }"
  14. >
  15. <image class="card-left-img" src="@/static/images/card-img2.png" mode="widthFix" />
  16. <view class="card-right-info">
  17. <text class="info-title">读者证号</text>
  18. <text class="info-num">{{ formatCardNo(item.bindValue) }}</text>
  19. <text class="default-tag" v-if="item.bindDefault">默认证</text>
  20. </view>
  21. <!-- 编辑模式显示单选框 -->
  22. <radio v-if="isEditMode" :value="item.bindValue" :checked="selectedValue === item.bindValue"/>
  23. <!-- 非编辑模式才显示:设置默认 + 二维码 -->
  24. <view class="card-setting" v-else>
  25. <button v-if="!item.bindDefault" type="default" size="mini" @click.stop="setDefaultCard(item.bindValue)">设置默认</button>
  26. <uni-icons class="erweima-style" custom-prefix="iconfont" type="icon-erweima" size="28" @click.stop="showQrcode(item.bindValue)"></uni-icons>
  27. </view>
  28. </view>
  29. <view class="add-card-btn" @click="toAddReaderCard" v-if="!isEditMode">
  30. <uni-icons type="plus" size="20" color="#01a4fe"></uni-icons>
  31. <text>新增读者证</text>
  32. </view>
  33. </view>
  34. <!-- 编辑模式显示底部解绑按钮 -->
  35. <button
  36. v-if="isEditMode"
  37. class="unbind-btn"
  38. :disabled="!selectedValue"
  39. :class="{disabled: !selectedValue}"
  40. @click="handleUnbind"
  41. >
  42. 确认解绑
  43. </button>
  44. <!-- 二维码弹窗 -->
  45. <uni-popup ref="popup" type="center" @maskClick="closePopup">
  46. <view class="qrcode-popup">
  47. <view class="qrcode-title">读者证二维码</view>
  48. <w-qrcode
  49. v-if="qrcodeText"
  50. :value="qrcodeText"
  51. :size="160"
  52. foreground="#333"
  53. background="#f5f5f5"
  54. />
  55. <view class="qrcode-num">{{ qrcodeText }}</view>
  56. <view class="close-btn" @click="closePopup">关闭</view>
  57. </view>
  58. </uni-popup>
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. FetchFindAllReaderBindByOpenId,
  64. FetchSetDefaultReadCard,
  65. FetchUnbindReadCard
  66. } from '@/api/user';
  67. const READLIST = 'reader-card-list';
  68. export default {
  69. data() {
  70. return {
  71. isEditMode: false,
  72. selectedValue: '',
  73. cardList: [],
  74. qrcodeText: '' // 二维码内容
  75. }
  76. },
  77. onShow() {
  78. this.getBindReaderCardList();
  79. },
  80. methods: {
  81. // 格式化读者证号
  82. formatCardNo(cardNo) {
  83. if (!cardNo) return '';
  84. const str = String(cardNo);
  85. const len = str.length;
  86. if (len > 8) {
  87. // 前2位 + 中间全部* + 后2位
  88. const front = str.substring(0, 2);
  89. const end = str.substring(len - 2);
  90. const star = '*'.repeat(len - 4); // 中间全部隐藏
  91. return front + star + end;
  92. } else {
  93. // 小于等于8:*** + 后2位
  94. return '***' + str.substring(len - 2);
  95. }
  96. },
  97. // 切换编辑模式 + 清空选中
  98. toggleEditMode() {
  99. this.isEditMode = !this.isEditMode;
  100. this.selectedValue = '';
  101. },
  102. // 获取列表
  103. async getBindReaderCardList() {
  104. try {
  105. const openId = uni.getStorageSync('wx_login_code');
  106. if (!openId) return;
  107. const res = await FetchFindAllReaderBindByOpenId({
  108. libcode: '1201',
  109. openId: openId
  110. });
  111. if (res.code === 200 && res.data.length > 0) {
  112. this.cardList = res.data;
  113. uni.setStorageSync(READLIST, res.data);
  114. } else {
  115. this.cardList = [];
  116. this.selectedValue = '';
  117. uni.setStorageSync(READLIST, []);
  118. }
  119. } catch (err) {
  120. this.cardList = uni.getStorageSync(READLIST) || [];
  121. }
  122. },
  123. // 点击卡片(仅编辑模式使用)
  124. handleSelectItem(value) {
  125. if (this.isEditMode) {
  126. this.selectedValue = this.selectedValue === value ? '' : value;
  127. }
  128. },
  129. async setDefaultCard(value) {
  130. const currentDefault = this.cardList.find(item => item.bindDefault === true);
  131. if (currentDefault && currentDefault.bindValue === value) {
  132. uni.showToast({ title: '当前已是默认证', icon: 'none' });
  133. return;
  134. }
  135. const openId = uni.getStorageSync('wx_login_code');
  136. uni.showModal({
  137. title: '提示',
  138. content: '确定设为默认读者证吗?',
  139. success: async (res) => {
  140. if (!res.confirm) return;
  141. try {
  142. await FetchSetDefaultReadCard({
  143. bindType: 'rdid',
  144. bindValue: value,
  145. libcode: '1201',
  146. openid: openId
  147. });
  148. uni.setStorageSync('currentReaderCard', value);
  149. await this.getBindReaderCardList();
  150. uni.showToast({ title: '设置成功', icon: 'success' });
  151. } catch (err) {
  152. uni.showToast({ title: '设置失败', icon: 'none' });
  153. }
  154. }
  155. });
  156. },
  157. // ========== 新功能:显示二维码 ==========
  158. showQrcode(bindValue) {
  159. this.qrcodeText = bindValue;
  160. this.$refs.popup.open();
  161. },
  162. closePopup() {
  163. console.log('关闭弹窗');
  164. this.qrcodeText = '';
  165. this.$refs.popup.close();
  166. },
  167. // 解绑(不变)
  168. async handleUnbind() {
  169. if (!this.selectedValue) {
  170. uni.showToast({ title: '请选择要解绑的读者证', icon: 'none' });
  171. return;
  172. }
  173. const openId = uni.getStorageSync('wx_login_code');
  174. const unbindItem = this.cardList.find(item => item.bindValue === this.selectedValue);
  175. const isUnbindDefault = unbindItem?.bindDefault === true;
  176. uni.showModal({
  177. title: '提示',
  178. content: `确定要解绑读者证【${this.selectedValue}】吗?`,
  179. success: async (res) => {
  180. if (!res.confirm) return;
  181. try {
  182. const result = await FetchUnbindReadCard({
  183. bindType: "rdid",
  184. bindValue: this.selectedValue,
  185. libcode: "1201",
  186. openid: openId
  187. });
  188. if (result.code === 200) {
  189. uni.showToast({ title: '解绑成功', icon: 'success' });
  190. this.selectedValue = '';
  191. await this.getBindReaderCardList();
  192. if (isUnbindDefault && this.cardList.length > 0) {
  193. const newValue = this.cardList[0].bindValue;
  194. await FetchSetDefaultReadCard({
  195. bindType: 'rdid',
  196. bindValue: newValue,
  197. libcode: '1201',
  198. openid: openId
  199. });
  200. uni.setStorageSync('currentReaderCard', newValue);
  201. await this.getBindReaderCardList();
  202. }
  203. if (this.cardList.length === 0) {
  204. setTimeout(() => uni.navigateBack(), 1500);
  205. }
  206. }
  207. } catch (err) {
  208. uni.showToast({ title: '解绑失败', icon: 'none' });
  209. }
  210. }
  211. });
  212. },
  213. toAddReaderCard() {
  214. uni.navigateTo({ url: "/pages/login/login" });
  215. },
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .reader-card{
  221. position: relative;
  222. min-height: 100vh;
  223. background-color: #f5f5f5;
  224. .card-top-bg{
  225. position: absolute;
  226. left: 0;
  227. top: 0;
  228. width: 100%;
  229. }
  230. .edit-btn{
  231. position: absolute;
  232. right: 20px;
  233. top: 20px;
  234. z-index: 100;
  235. font-size: 15px;
  236. }
  237. // 读者证列表
  238. .card-list{
  239. position: absolute;
  240. left: 0;
  241. top: 60px;
  242. width: calc(100% - 24px);
  243. height: calc(100vh - 195px);
  244. overflow-y: auto;
  245. padding: 12px;
  246. z-index: 999;
  247. .card-list-item{
  248. display: flex;
  249. justify-content: space-between;
  250. align-items: center;
  251. padding: 10px;
  252. margin-bottom: 12px;
  253. border: 2px solid #C6C6E2;
  254. border-radius: 8px;
  255. background: rgba(241,241,249,0.4);
  256. cursor: pointer;
  257. transition: all 0.2s;
  258. &.active{
  259. border-color: #01a4fe;
  260. background: rgba(1, 164, 254, 0.1);
  261. }
  262. .card-left-img{
  263. width: 80px;
  264. margin-right: 12px;
  265. display: block;
  266. }
  267. .card-right-info{
  268. flex: 1;
  269. display: flex;
  270. flex-direction: column;
  271. .info-title{
  272. font-size: 16px;
  273. color: #333;
  274. font-weight: bold;
  275. padding-bottom: 4px;
  276. }
  277. .info-num{
  278. font-size: 14px;
  279. color: #999;
  280. }
  281. .default-tag{
  282. width: 46px;
  283. font-size: 12px;
  284. color: #01a4fe;
  285. border: 1px solid #01a4fe;
  286. border-radius: 4px;
  287. padding: 2px 0;
  288. text-align: center;
  289. display: inline-block;
  290. margin-top: 4px;
  291. }
  292. }
  293. }
  294. }
  295. .add-card-btn {
  296. display: flex;
  297. align-items: center;
  298. justify-content: center;
  299. margin-top: 15px;
  300. height: 44px;
  301. border: 1px dashed #01a4fe;
  302. border-radius: 8px;
  303. color: #01a4fe;
  304. font-size: 15px;
  305. uni-icons {
  306. margin-right: 6px;
  307. }
  308. }
  309. .unbind-btn{
  310. position: fixed;
  311. bottom: 40px;
  312. left: 0;
  313. right: 0;
  314. width: calc(100% - 40px);
  315. margin: 0 auto;
  316. padding: 4px 0;
  317. color: #fff;
  318. background-color: #01a4fe;
  319. border-radius: 23px;
  320. font-size: 16px;
  321. &.disabled{
  322. background-color: #ccc;
  323. }
  324. }
  325. }
  326. .card-setting{
  327. display: flex;
  328. flex-direction: column;
  329. align-items: center;
  330. justify-content: center;
  331. button{
  332. padding: 0 8px !important;
  333. margin-bottom: 6px;
  334. font-size: 12px;
  335. }
  336. ::v-deep .icon-erweima{
  337. color: #999 !important;
  338. }
  339. }
  340. </style>