index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="content">
  3. <view class="uni-margin-wrap">
  4. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#DE868F" indicator-active-color="#fff"
  5. :autoplay="true" :interval="1000" :duration="500">
  6. <swiper-item>
  7. <view class="swiper-item">功能介绍1</view>
  8. </swiper-item>
  9. <swiper-item>
  10. <view class="swiper-item">功能介绍2</view>
  11. </swiper-item>
  12. <swiper-item>
  13. <view class="swiper-item">功能介绍3</view>
  14. </swiper-item>
  15. </swiper>
  16. </view>
  17. <form class="form-area">
  18. <view class="form-area-item">
  19. <text class="form-area-item-text">视频名称</text>
  20. <input type="text" v-model="videoName" placeholder="请输入视频名称">
  21. </view>
  22. <!-- <view class="form-area-item" :key="timeStamp">
  23. <text class="form-area-item-text">选择您的形象</text>
  24. <button @click="chooseFile" class="cu-btn bg-red">选择文件</button>
  25. <text class="file-name" v-if="fileInfo.name">{{fileInfo.name}}</text>
  26. <text class="none-file" v-if="!showPerson">未选择文件</text>
  27. </view> -->
  28. <view class="form-area-item">
  29. <text class="form-area-item-text">选择您的形象</text>
  30. <button @click="chooseImage" class="cu-btn bg-red">选择图片</button>
  31. <text class="none-file" v-if="!imagePath">未选择图片</text>
  32. <image :src="imagePath" v-else mode="aspectFit" style="width: 30px; height: 30px;margin-left:10px" />
  33. </view>
  34. <!-- <view class="form-area-item">
  35. <text class="form-area-item-text">选择模板</text>
  36. <uni-data-select v-model="modelIndex" :localdata="array" @change="bindPickerChange"></uni-data-select>
  37. <CustomModal :visible="isModalVisible" :message="modalMessage" :imageSrc="modalImageSrc" @confirm="onConfirm"
  38. @cancel="onCancel" />
  39. </view> -->
  40. <view class="form-area-item">
  41. <text class="form-area-item-text">视频内容</text>
  42. <uni-data-checkbox selectedColor="#BD3124" selectedTextColor="#BD3124" v-model="current"
  43. :localdata="videoContent" />
  44. </view>
  45. <view class="form-area-item" v-if="current=='text'">
  46. <textarea v-model="videoText" placeholder="请输入视频中的文字内容" />
  47. </view>
  48. <view class="form-area-item" v-if="current=='text'">
  49. <text class="form-area-item-text">音色选择</text>
  50. <uni-data-checkbox selectedColor="#BD3124" selectedTextColor="#BD3124" v-model="timbre"
  51. :localdata="timbreContent" />
  52. </view>
  53. <view class="form-area-item" v-if="current=='record'">
  54. <button @click="toggleRecording">{{ isRecording ? '停止录音' : '开始录音' }}</button>
  55. <!-- <view v-if="audioPath" class="audio-bar" @click="playAudio">
  56. 🎵 录音文件(点击播放)
  57. </view> -->
  58. </view>
  59. <audio v-if="audioPath" class="audio-bar" :src="audioPath" name="语音试听" poster="../static/images/xijiao/avator.png"
  60. :action="audioAction" controls></audio>
  61. </form>
  62. <view class="btn-area">
  63. <button @click="jumpToList" class="bg-red lg round create-project">生成数字人视频</button>
  64. <uni-popup ref="alertDialog" type="dialog">
  65. <uni-popup-dialog type="warning" cancelText="确定" title="提示" :content="missingContent"
  66. @close="dialogClose"></uni-popup-dialog>
  67. </uni-popup>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. // import CustomModal from '../components/CustomModal.vue';
  73. import {
  74. uploadPerson
  75. } from "@/api/system/user"
  76. import store from '@/store'
  77. const recorderManager = uni.getRecorderManager();
  78. const innerAudioContext = uni.createInnerAudioContext();
  79. innerAudioContext.autoplay = true;
  80. export default {
  81. // components: {
  82. // CustomModal
  83. // },
  84. data() {
  85. return {
  86. videoName: '',
  87. fileInfo: {},
  88. videoContent: [{
  89. value: 'text',
  90. text: '文字输入'
  91. },
  92. {
  93. value: 'record',
  94. text: '语音录入'
  95. }
  96. ],
  97. current: 'text',
  98. imagePath: '',
  99. isRecording: false,
  100. audioPath: null,
  101. recorderManager: null,
  102. innerAudioContext: null,
  103. showPerson: false,
  104. timeStamp: null,
  105. audioAction: {
  106. method: 'pause'
  107. },
  108. videoText: '',
  109. missingContent: [],
  110. timbre: 'a',
  111. timbreContent: [{
  112. value: 'a',
  113. text: 'timbre1'
  114. },
  115. {
  116. value: 'b',
  117. text: 'timbre2'
  118. }
  119. ],
  120. personPath: ''
  121. }
  122. },
  123. onLoad() {
  124. this.recorderManager = uni.getRecorderManager();
  125. this.innerAudioContext = uni.createInnerAudioContext();
  126. // 监听录音停止
  127. this.recorderManager.onStop((res) => {
  128. console.log('录音结束,临时路径:', res.tempFilePath);
  129. this.audioPath = res.tempFilePath; // 替换为新录音路径
  130. this.isRecording = false;
  131. });
  132. // 监听录音错误
  133. this.recorderManager.onError((err) => {
  134. uni.showToast({
  135. title: '录音出错',
  136. icon: 'none'
  137. });
  138. });
  139. },
  140. onShow() {
  141. this.timeStamp = new Date().getTime()
  142. this.fileInfo.path = uni.getStorageSync('filePath');
  143. this.fileInfo.name = uni.getStorageSync('fileName');
  144. if (this.fileInfo.name) this.showPerson = true
  145. },
  146. methods: {
  147. /* chooseFile() {
  148. uni.navigateTo({
  149. url: "/pages/root-filelist/root-filelist",
  150. });
  151. }, */
  152. async chooseImage() {
  153. const that = this;
  154. uni.chooseImage({
  155. count: 1,
  156. sizeType: ['original', 'compressed'],
  157. sourceType: ['album', 'camera'],
  158. success: function(res) {
  159. that.imagePath = res.tempFilePaths[0];
  160. that.uploadImagePath()
  161. },
  162. fail: function(err) {
  163. uni.showToast({
  164. title: '图片选择失败',
  165. icon: 'none'
  166. });
  167. }
  168. });
  169. },
  170. /* bindPickerChange(e) {
  171. const tempOption = this.array.find(item => item.value == e).text;
  172. this.modalMessage = `您选择的是: ${tempOption}`;
  173. this.modalImageSrc = '../static/images/xijiao/avator.png';
  174. this.isModalVisible = true;
  175. this.modelIndex = e
  176. },
  177. onConfirm() {
  178. this.isModalVisible = false;
  179. },
  180. onCancel() {
  181. this.isModalVisible = false;
  182. }, */
  183. radioChange(evt) {
  184. for (let i = 0; i < this.videoContent.length; i++) {
  185. if (this.videoContent[i].value === evt.detail.value) {
  186. this.current = i;
  187. break;
  188. }
  189. }
  190. },
  191. toggleRecording() {
  192. if (this.isRecording) {
  193. this.recorderManager.stop();
  194. } else {
  195. // 开始录音前,如果已有录音则清空
  196. if (this.audioPath) {
  197. this.audioPath = null;
  198. }
  199. // 开始录音
  200. this.recorderManager.start({
  201. duration: 600000, // 最大录音时间(毫秒)
  202. sampleRate: 44100,
  203. numberOfChannels: 1,
  204. encodeBitRate: 192000,
  205. format: 'wav',
  206. });
  207. this.isRecording = true;
  208. }
  209. },
  210. // playAudio() {
  211. // if (!this.audioPath) {
  212. // uni.showToast({
  213. // title: '没有可播放的录音',
  214. // icon: 'none'
  215. // });
  216. // return;
  217. // }
  218. // this.innerAudioContext.src = this.audioPath;
  219. // this.innerAudioContext.play();
  220. // },
  221. uploadImagePath() {
  222. let data = {
  223. file: this.imagePath
  224. }
  225. uploadPerson(data).then(response => {
  226. this.personPath = response.data.url
  227. })
  228. },
  229. jumpToList() {
  230. let missingFields = [];
  231. if (!this.videoName.trim()) {
  232. missingFields.push('视频名称');
  233. }
  234. // if (!this.fileInfo.path) {
  235. // missingFields.push('人物形象');
  236. // }
  237. if (!this.imagePath) {
  238. missingFields.push('人物形象');
  239. }
  240. // if (!this.modelIndex) {
  241. // missingFields.push('视频模板');
  242. // }
  243. const hasContent = this.videoText.trim() !== '' && this.timbre;
  244. const hasVoice = this.audioPath;
  245. if (!hasContent && !hasVoice) {
  246. missingFields.push('文字内容或语音输入');
  247. }
  248. if (missingFields.length > 0) {
  249. this.missingContent = `请确定:${missingFields.join('、')}是否填写完整!`
  250. this.$refs.alertDialog.open()
  251. return;
  252. }
  253. uni.navigateTo({
  254. url: 'list/creatingVideo/creatingVideo',
  255. });
  256. },
  257. dialogClose() {
  258. console.log('点击关闭')
  259. },
  260. }
  261. }
  262. </script>
  263. <style scoped lang="scss">
  264. .content {
  265. display: flex;
  266. flex-direction: column;
  267. /* align-items: center;
  268. justify-content: center; */
  269. }
  270. .uni-margin-wrap {
  271. width: 690rpx;
  272. width: 100%;
  273. }
  274. .swiper {
  275. height: 300rpx;
  276. }
  277. .swiper-item {
  278. display: block;
  279. height: 300rpx;
  280. line-height: 300rpx;
  281. text-align: center;
  282. background-color: #BD3124;
  283. color: #fff;
  284. }
  285. .form-area {
  286. padding: 20px;
  287. .form-area-item {
  288. display: flex;
  289. flex-direction: row;
  290. margin-top: 30px;
  291. align-items: center;
  292. .form-area-item-text {
  293. width: 120px;
  294. }
  295. /deep/ uni-input {
  296. border: 1px solid #e5e5e5;
  297. border-radius: 4px;
  298. height: 30px;
  299. width: 200px;
  300. }
  301. /deep/ uni-picker {
  302. border-bottom: 1px solid #aaa;
  303. height: 30px;
  304. width: 200px;
  305. display: flex;
  306. align-items: center;
  307. }
  308. /deep/ uni-radio-group,
  309. /deep/ uni-label {
  310. display: flex;
  311. align-items: center;
  312. }
  313. /deep/ uni-label {
  314. margin-right: 10px;
  315. }
  316. /deep/ textarea {
  317. border: 1px solid #aaa;
  318. border-radius: 4px;
  319. width: 320px;
  320. padding: 5px;
  321. margin: 0 auto;
  322. }
  323. .none-file {
  324. margin-left: 10px;
  325. color: #aaa;
  326. }
  327. .file-name {
  328. margin-left: 10px;
  329. width: 50px;
  330. overflow: hidden;
  331. white-space: nowrap;
  332. text-overflow: ellipsis;
  333. }
  334. }
  335. }
  336. .btn-area {
  337. display: flex;
  338. justify-content: center;
  339. margin: 20px auto;
  340. width: 100%;
  341. }
  342. .audio-bar {
  343. text-align: center;
  344. display: block;
  345. margin-top: 10px;
  346. }
  347. /deep/ .uni-border-left {
  348. display: none;
  349. }
  350. </style>