code-storage-add.vue 6.2 KB

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