code-storage-add.vue 5.5 KB

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