voice_upload.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>播客上传声音</title>
  7. </head>
  8. <body>
  9. <div>
  10. <a href="/qrlogin-nocookie.html">
  11. 如果没登录,请先登录
  12. </a>
  13. </div>
  14. <div id="app">
  15. <ul>
  16. <li v-for="(item,index) in voicelist" @click="currentVoiceIndex=index"
  17. :class="{active:currentVoiceIndex===index}">
  18. <img :src="item.coverUrl" style="width:50px;width:50px;" />
  19. <ul>
  20. <li v-for="(item2,index) in item.voiceListData">
  21. {{item2.voiceName}}
  22. </li>
  23. </ul>
  24. {{item.voiceListName}}
  25. </li>
  26. </ul>
  27. <input v-model="songName" placeholder="请输入声音名称" />
  28. <input v-model="description" placeholder="请输入介绍" />
  29. <input type="file" name="songFile" />
  30. <button @click="submit">上传</button>
  31. </div>
  32. <script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
  33. <script src="https://cdn.jsdelivr.net/npm/vue"></script>
  34. <script>
  35. Vue.createApp({
  36. data() {
  37. return {
  38. songName: '',
  39. description: '',
  40. voicelist: [],
  41. cookieToken: '',
  42. currentVoiceIndex: 0,
  43. }
  44. },
  45. created() {
  46. this.getData()
  47. },
  48. computed: {
  49. currentVoice() {
  50. // {
  51. // voiceListId: '',
  52. // coverImgId: '',
  53. // categoryId: '',
  54. // secondCategoryId: '',
  55. // }
  56. return this.voicelist[this.currentVoiceIndex]
  57. },
  58. },
  59. methods: {
  60. submit() {
  61. console.log('submit')
  62. const file = document.querySelector('input[type=file]').files[0]
  63. this.upload(file)
  64. },
  65. async getData() {
  66. const res = await axios({
  67. url: `/voicelist/search?cookie=${localStorage.getItem('cookie')}`,
  68. })
  69. console.log(res.data.data)
  70. this.voicelist = res.data.data.list
  71. this.voicelist.map(async i => {
  72. const res2 = await axios({
  73. url: `/voicelist/list?voiceListId=${i.voiceListId}&limit=5`,
  74. })
  75. i.voiceListData = res2.data.data.list
  76. console.log(res2);
  77. })
  78. },
  79. upload(file) {
  80. var formData = new FormData()
  81. formData.append('songFile', file)
  82. axios({
  83. method: 'post',
  84. url: `/voice/upload?time=${Date.now()}&cookie=${localStorage.getItem('cookie')
  85. }&songName=${this.songName}&voiceListId=${this.currentVoice.voiceListId
  86. }&categoryId=${this.currentVoice.categoryId}&coverImgId=${this.currentVoice.coverImgId
  87. }&secondCategoryId=${this.currentVoice.secondCategoryId}&description=${this.description
  88. }&privacy=1`,
  89. headers: {
  90. 'Content-Type': 'multipart/form-data',
  91. },
  92. data: formData,
  93. })
  94. .then((res) => {
  95. alert(`${file.name} 上传成功`)
  96. if (currentIndx >= fileLength) {
  97. console.log('上传完毕')
  98. }
  99. })
  100. .catch(async (err) => {
  101. console.log(err)
  102. })
  103. },
  104. },
  105. }).mount('#app')
  106. </script>
  107. <style>
  108. ul li {
  109. cursor: pointer;
  110. }
  111. ul li.active {
  112. color: red;
  113. }
  114. </style>
  115. </body>
  116. </html>