code-storage-add.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class="container">
  3. <!-- 书籍信息展示区域 -->
  4. <view class="book-info-section" v-if="bookInfo.bookName">
  5. <view class="book-cover">
  6. <image :src="bookInfo.cover || '/static/img/default-book.png'" class="cover-image" mode="aspectFit" />
  7. </view>
  8. <view class="book-details">
  9. <text class="book-title">{{ bookInfo.bookName }}</text>
  10. <text class="book-isbn">{{ bookInfo.isbn }}</text>
  11. <text class="book-publisher">{{ bookInfo.publish }}</text>
  12. <text class="book-author">{{ bookInfo.author }}</text>
  13. <text class="book-date">{{ bookInfo.pubDate }}</text>
  14. </view>
  15. </view>
  16. <!-- 上传图片区域 -->
  17. <view class="upload-section">
  18. <view class="upload-label">上传图片</view>
  19. <view class="upload-content">
  20. <cy-upload :filename="form.imgUrl" @update:filename="form.imgUrl = $event" @success="onUploadSuccess"
  21. name="imgUrl" :maxCount="1" :max-size="1024 * 1024">
  22. </cy-upload>
  23. </view>
  24. </view>
  25. <!-- 底部按钮 -->
  26. <view class="fixed-bottom">
  27. <u-button size="large" type="warning" @click="cancelForm" text="取消" class="cancel-button" />
  28. <u-button size="large" type="success" @click="submitForm" text="提交" class="submit-button" />
  29. </view>
  30. </view>
  31. </template>
  32. <script setup>
  33. import {
  34. ref,
  35. reactive,
  36. onUnmounted
  37. } from 'vue';
  38. import {
  39. onLoad,
  40. onShow
  41. } from '@dcloudio/uni-app'
  42. import cyUpload from '@/components/cy-upload/index.vue'
  43. const form = ref({
  44. "isbn": "",
  45. "imgUrl": ""
  46. });
  47. // 书籍信息
  48. const bookInfo = ref({});
  49. // 图片上传状态
  50. const isImageUploaded = ref(false);
  51. onShow(() => {
  52. // 从本地存储获取书籍信息
  53. const storedInfo = uni.getStorageSync('bookInfo');
  54. bookInfo.value = storedInfo
  55. })
  56. // 图片上传成功回调
  57. function onUploadSuccess(result) {
  58. console.log('图片上传成功:', result);
  59. isImageUploaded.value = true;
  60. }
  61. // 取消操作
  62. function cancelForm() {
  63. uni.navigateBack();
  64. }
  65. function submitForm() {
  66. if (!form.value.imgUrl || form.value.imgUrl.length === 0) {
  67. uni.$u.toast('请先上传图片');
  68. return;
  69. }
  70. if (!isImageUploaded.value) {
  71. uni.$u.toast('图片正在上传中,请稍候');
  72. return;
  73. }
  74. // 这里应该调用实际的API接口
  75. uni.$u.http.post('/activation/bookActivationInfo/activationAdd', {
  76. isbn: bookInfo.value.isbn,
  77. img: form.value.imgUrl[0]
  78. }).then(res => {
  79. if (res.code == 200) {
  80. uni.$u.toast('提交成功')
  81. let text = '提交成功,请销毁激活码'
  82. uni.$u.ttsModule.speak(text)
  83. // 返回上一页
  84. uni.navigateBack();
  85. } else {
  86. let text = '提交失败:' + (res.msg || '未知错误')
  87. uni.$u.toast(text)
  88. uni.$u.ttsModule.speak(text)
  89. }
  90. }).catch(err => {
  91. uni.$u.ttsModule.speak('网络错误')
  92. })
  93. }
  94. // #ifdef APP-PLUS
  95. const { unregister } = uni.$u.useEventListener((e) => {
  96. form.value.isbn = e.barcode;
  97. queryBookInfo(e.barcode);
  98. });
  99. // #endif
  100. onUnmounted(() => {
  101. // #ifdef APP-PLUS
  102. unregister();
  103. // #endif
  104. });
  105. </script>
  106. <style>
  107. page {
  108. background-color: #ffffff;
  109. }
  110. </style>
  111. <style scoped>
  112. .container {
  113. display: flex;
  114. flex-direction: column;
  115. padding: 20px;
  116. min-height: 100vh;
  117. background-color: #f5f5f5;
  118. }
  119. /* 书籍信息展示区域 */
  120. .book-info-section {
  121. display: flex;
  122. background-color: white;
  123. border-radius: 6px;
  124. padding: 20rpx;
  125. margin-bottom: 30rpx;
  126. }
  127. .book-cover {
  128. width: 150rpx;
  129. /* height: 160rpx; */
  130. margin-right: 30rpx;
  131. flex-shrink: 0;
  132. }
  133. .cover-image {
  134. width: 100%;
  135. height: 100%;
  136. border-radius: 8rpx;
  137. }
  138. .book-details {
  139. flex: 1;
  140. display: flex;
  141. flex-direction: column;
  142. justify-content: space-between;
  143. }
  144. .book-title {
  145. font-size: 32rpx;
  146. font-weight: bold;
  147. color: #333;
  148. margin-bottom: 8rpx;
  149. }
  150. .book-isbn {
  151. font-size: 28rpx;
  152. color: #666;
  153. margin-bottom: 6rpx;
  154. }
  155. .book-publisher {
  156. font-size: 26rpx;
  157. color: #666;
  158. margin-bottom: 6rpx;
  159. }
  160. .book-author {
  161. font-size: 26rpx;
  162. color: #666;
  163. margin-bottom: 6rpx;
  164. }
  165. .book-date {
  166. font-size: 24rpx;
  167. color: #999;
  168. }
  169. /* 上传图片区域 */
  170. .upload-section {
  171. background-color: white;
  172. border-radius: 12px;
  173. padding: 30rpx;
  174. margin-bottom: 120rpx;
  175. }
  176. .upload-label {
  177. font-size: 32rpx;
  178. font-weight: bold;
  179. color: #333;
  180. margin-bottom: 20rpx;
  181. }
  182. .upload-content {
  183. display: flex;
  184. gap: 30rpx;
  185. align-items: flex-start;
  186. }
  187. /* 提示框样式 */
  188. .tip-box {
  189. display: flex;
  190. background-color: #fff3cd;
  191. border: 1px solid #ffeaa7;
  192. border-radius: 8px;
  193. padding: 20rpx;
  194. flex: 1;
  195. align-items: flex-start;
  196. }
  197. .tip-number {
  198. background-color: #f39c12;
  199. color: white;
  200. width: 40rpx;
  201. height: 40rpx;
  202. border-radius: 50%;
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. font-size: 24rpx;
  207. font-weight: bold;
  208. margin-right: 20rpx;
  209. flex-shrink: 0;
  210. }
  211. .tip-content {
  212. flex: 1;
  213. display: flex;
  214. flex-direction: column;
  215. }
  216. .tip-text {
  217. font-size: 24rpx;
  218. color: #856404;
  219. line-height: 1.4;
  220. margin-bottom: 8rpx;
  221. }
  222. .tip-success {
  223. font-size: 24rpx;
  224. color: #155724;
  225. line-height: 1.4;
  226. margin-bottom: 8rpx;
  227. }
  228. .tip-limit {
  229. font-size: 24rpx;
  230. color: #856404;
  231. line-height: 1.4;
  232. margin-bottom: 15rpx;
  233. }
  234. .tip-author {
  235. font-size: 20rpx;
  236. color: #6c757d;
  237. }
  238. </style>