├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

upload.vue 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view class="upload-container">
  3. <view class="header">作品管理</view>
  4. <view class="tabs">
  5. <view
  6. :class="{ active: activeTab === 'novel' }"
  7. @click="activeTab = 'novel'"
  8. >
  9. 上传整本小说
  10. </view>
  11. <view
  12. :class="{ active: activeTab === 'chapter' }"
  13. @click="activeTab = 'chapter'"
  14. >
  15. 上传章节
  16. </view>
  17. </view>
  18. <!-- 整本小说上传 -->
  19. <view v-if="activeTab === 'novel'" class="form-section">
  20. <view class="form-item">
  21. <text class="label">小说标题</text>
  22. <input v-model="novelForm.title" placeholder="请输入小说标题" />
  23. </view>
  24. <view class="form-item">
  25. <text class="label">选择作者</text>
  26. <picker @change="bindAuthorChange" :value="authorIndex" :range="authors">
  27. <view class="picker">
  28. {{ novelForm.authorName || '请选择作者' }}
  29. </view>
  30. </picker>
  31. </view>
  32. <view class="form-item">
  33. <text class="label">上传文件</text>
  34. <button class="upload-btn" @click="chooseNovelFile">选择TXT文件</button>
  35. <text v-if="novelForm.file" class="file-name">{{ novelForm.file.name }}</text>
  36. </view>
  37. <button class="submit-btn" @click="submitNovel">提交上传</button>
  38. </view>
  39. <!-- 章节上传 -->
  40. <view v-if="activeTab === 'chapter'" class="form-section">
  41. <view class="form-item">
  42. <text class="label">选择小说</text>
  43. <picker @change="bindNovelChange" :value="novelIndex" :range="novels">
  44. <view class="picker">
  45. {{ chapterForm.novelTitle || '请选择小说' }}
  46. </view>
  47. </picker>
  48. </view>
  49. <view class="form-item">
  50. <text class="label">章节序号</text>
  51. <input v-model="chapterForm.chapterOrder" placeholder="自动生成或手动指定" />
  52. </view>
  53. <view class="form-item">
  54. <text class="label">上传章节</text>
  55. <button class="upload-btn" @click="chooseChapterFile">选择TXT文件</button>
  56. <text v-if="chapterForm.file" class="file-name">{{ chapterForm.file.name }}</text>
  57. </view>
  58. <button class="submit-btn" @click="submitChapter">提交上传</button>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. export default {
  64. data() {
  65. return {
  66. activeTab: 'novel',
  67. authors: [],
  68. authorIndex: -1,
  69. novels: [],
  70. novelIndex: -1,
  71. novelForm: {
  72. title: '',
  73. authorId: null,
  74. authorName: '',
  75. file: null
  76. },
  77. chapterForm: {
  78. novelId: null,
  79. novelTitle: '',
  80. chapterOrder: '',
  81. file: null
  82. }
  83. };
  84. },
  85. async onLoad() {
  86. // 加载作者列表
  87. const authorRes = await this.$api.getAuthorList();
  88. this.authors = authorRes.data.map(a => a.nickName);
  89. // 加载小说列表
  90. const novelRes = await this.$api.getNovelList();
  91. this.novels = novelRes.rows.map(n => n.title);
  92. },
  93. methods: {
  94. // 作者选择
  95. bindAuthorChange(e) {
  96. this.authorIndex = e.detail.value;
  97. this.novelForm.authorId = this.authors[this.authorIndex].userId;
  98. this.novelForm.authorName = this.authors[this.authorIndex].nickName;
  99. },
  100. // 小说选择
  101. bindNovelChange(e) {
  102. this.novelIndex = e.detail.value;
  103. this.chapterForm.novelId = this.novels[this.novelIndex].id;
  104. this.chapterForm.novelTitle = this.novels[this.novelIndex].title;
  105. },
  106. // 选择文件
  107. chooseNovelFile() {
  108. uni.chooseFile({
  109. count: 1,
  110. extension: ['.txt'],
  111. success: (res) => {
  112. this.novelForm.file = res.tempFiles[0];
  113. }
  114. });
  115. },
  116. chooseChapterFile() {
  117. uni.chooseFile({
  118. count: 1,
  119. extension: ['.txt'],
  120. success: (res) => {
  121. this.chapterForm.file = res.tempFiles[0];
  122. }
  123. });
  124. },
  125. // 提交表单
  126. async submitNovel() {
  127. if (!this.novelForm.title || !this.novelForm.authorId || !this.novelForm.file) {
  128. uni.showToast({ title: '请填写完整信息', icon: 'none' });
  129. return;
  130. }
  131. try {
  132. const formData = new FormData();
  133. formData.append('title', this.novelForm.title);
  134. formData.append('authorId', this.novelForm.authorId);
  135. formData.append('file', this.novelForm.file);
  136. const res = await this.$api.uploadNovel(formData);
  137. uni.showToast({ title: '上传成功' });
  138. this.resetNovelForm();
  139. } catch (e) {
  140. uni.showToast({ title: '上传失败: ' + e.message, icon: 'none' });
  141. }
  142. },
  143. async submitChapter() {
  144. if (!this.chapterForm.novelId || !this.chapterForm.file) {
  145. uni.showToast({ title: '请填写完整信息', icon: 'none' });
  146. return;
  147. }
  148. try {
  149. const formData = new FormData();
  150. formData.append('novelId', this.chapterForm.novelId);
  151. if (this.chapterForm.chapterOrder) {
  152. formData.append('chapterOrder', this.chapterForm.chapterOrder);
  153. }
  154. formData.append('file', this.chapterForm.file);
  155. const res = await this.$api.uploadChapter(formData);
  156. uni.showToast({ title: '章节上传成功' });
  157. this.resetChapterForm();
  158. } catch (e) {
  159. uni.showToast({ title: '上传失败: ' + e.message, icon: 'none' });
  160. }
  161. },
  162. resetNovelForm() {
  163. this.novelForm = {
  164. title: '',
  165. authorId: null,
  166. authorName: '',
  167. file: null
  168. };
  169. this.authorIndex = -1;
  170. },
  171. resetChapterForm() {
  172. this.chapterForm = {
  173. novelId: null,
  174. novelTitle: '',
  175. chapterOrder: '',
  176. file: null
  177. };
  178. this.novelIndex = -1;
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. .upload-container {
  185. padding: 30rpx;
  186. }
  187. .header {
  188. font-size: 36rpx;
  189. font-weight: bold;
  190. margin-bottom: 40rpx;
  191. text-align: center;
  192. color: #3a8ee6; /* 若依主题色 */
  193. }
  194. .tabs {
  195. display: flex;
  196. margin-bottom: 30rpx;
  197. border-bottom: 1rpx solid #eee;
  198. view {
  199. flex: 1;
  200. text-align: center;
  201. padding: 20rpx 0;
  202. font-size: 30rpx;
  203. color: #666;
  204. &.active {
  205. color: #3a8ee6;
  206. font-weight: bold;
  207. border-bottom: 4rpx solid #3a8ee6;
  208. }
  209. }
  210. }
  211. .form-section {
  212. background: #fff;
  213. border-radius: 16rpx;
  214. padding: 30rpx;
  215. box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
  216. }
  217. .form-item {
  218. margin-bottom: 40rpx;
  219. padding-bottom: 30rpx;
  220. border-bottom: 1rpx solid #f5f5f5;
  221. .label {
  222. display: block;
  223. font-size: 28rpx;
  224. margin-bottom: 20rpx;
  225. color: #333;
  226. font-weight: 500;
  227. }
  228. input, .picker {
  229. width: 100%;
  230. height: 80rpx;
  231. font-size: 28rpx;
  232. padding: 0 20rpx;
  233. border: 1rpx solid #ddd;
  234. border-radius: 8rpx;
  235. box-sizing: border-box;
  236. }
  237. .picker {
  238. display: flex;
  239. align-items: center;
  240. }
  241. }
  242. .upload-btn {
  243. background: #f8f8f8;
  244. color: #3a8ee6;
  245. font-size: 26rpx;
  246. height: 80rpx;
  247. line-height: 80rpx;
  248. border: 1rpx dashed #3a8ee6;
  249. border-radius: 8rpx;
  250. }
  251. .file-name {
  252. display: block;
  253. margin-top: 15rpx;
  254. font-size: 26rpx;
  255. color: #666;
  256. overflow: hidden;
  257. text-overflow: ellipsis;
  258. white-space: nowrap;
  259. }
  260. .submit-btn {
  261. background: #3a8ee6;
  262. color: white;
  263. height: 90rpx;
  264. line-height: 90rpx;
  265. border-radius: 45rpx;
  266. font-size: 32rpx;
  267. margin-top: 50rpx;
  268. }
  269. </style>