code-storage-add.vue 5.8 KB

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