index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. const recorderManager = uni.getRecorderManager();
  77. const innerAudioContext = uni.createInnerAudioContext();
  78. innerAudioContext.autoplay = true;
  79. export default {
  80. // components: {
  81. // CustomModal
  82. // },
  83. data() {
  84. return {
  85. videoName: '',
  86. fileInfo: {},
  87. // array: [{
  88. // value: 'ceshi1',
  89. // text: 'demo1'
  90. // },
  91. // {
  92. // value: 'ceshi2',
  93. // text: 'demo3'
  94. // },
  95. // ],
  96. // modelIndex: undefined,
  97. // isModalVisible: false,
  98. // modalMessage: '',
  99. // modalImageSrc: '',
  100. videoContent: [{
  101. value: 'text',
  102. text: '文字输入'
  103. },
  104. {
  105. value: 'record',
  106. text: '语音录入'
  107. }
  108. ],
  109. current: 'text',
  110. imagePath: '',
  111. isRecording: false,
  112. audioPath: null,
  113. recorderManager: null,
  114. innerAudioContext: null,
  115. showPerson: false,
  116. timeStamp: null,
  117. audioAction: {
  118. method: 'pause'
  119. },
  120. videoText: '',
  121. missingContent: [],
  122. timbre:'a',
  123. timbreContent: [{
  124. value: 'a',
  125. text: 'timbre1'
  126. },
  127. {
  128. value: 'b',
  129. text: 'timbre2'
  130. }
  131. ],
  132. }
  133. },
  134. onLoad() {
  135. this.recorderManager = uni.getRecorderManager();
  136. this.innerAudioContext = uni.createInnerAudioContext();
  137. // 监听录音停止
  138. this.recorderManager.onStop((res) => {
  139. console.log('录音结束,临时路径:', res.tempFilePath);
  140. this.audioPath = res.tempFilePath; // 替换为新录音路径
  141. this.isRecording = false;
  142. });
  143. // 监听录音错误
  144. this.recorderManager.onError((err) => {
  145. uni.showToast({
  146. title: '录音出错',
  147. icon: 'none'
  148. });
  149. console.error('录音错误:', err);
  150. });
  151. },
  152. onShow() {
  153. this.timeStamp = new Date().getTime()
  154. this.fileInfo.path = uni.getStorageSync('filePath');
  155. this.fileInfo.name = uni.getStorageSync('fileName');
  156. if (this.fileInfo.name) this.showPerson = true
  157. },
  158. methods: {
  159. /* chooseFile() {
  160. uni.navigateTo({
  161. url: "/pages/root-filelist/root-filelist",
  162. });
  163. }, */
  164. async chooseImage() {
  165. const that = this;
  166. uni.chooseImage({
  167. count: 1,
  168. sizeType: ['original', 'compressed'],
  169. sourceType: ['album', 'camera'],
  170. success: function(res) {
  171. that.imagePath = res.tempFilePaths[0];
  172. },
  173. fail: function(err) {
  174. console.error('图片选择失败:', err);
  175. uni.showToast({
  176. title: '图片选择失败',
  177. icon: 'none'
  178. });
  179. }
  180. });
  181. },
  182. /* bindPickerChange(e) {
  183. const tempOption = this.array.find(item => item.value == e).text;
  184. this.modalMessage = `您选择的是: ${tempOption}`;
  185. this.modalImageSrc = '../static/images/xijiao/avator.png';
  186. this.isModalVisible = true;
  187. this.modelIndex = e
  188. },
  189. onConfirm() {
  190. this.isModalVisible = false;
  191. },
  192. onCancel() {
  193. this.isModalVisible = false;
  194. }, */
  195. radioChange(evt) {
  196. for (let i = 0; i < this.videoContent.length; i++) {
  197. if (this.videoContent[i].value === evt.detail.value) {
  198. this.current = i;
  199. break;
  200. }
  201. }
  202. },
  203. toggleRecording() {
  204. if (this.isRecording) {
  205. this.recorderManager.stop();
  206. } else {
  207. // 开始录音前,如果已有录音则清空
  208. if (this.audioPath) {
  209. this.audioPath = null;
  210. }
  211. // 开始录音
  212. this.recorderManager.start({
  213. duration: 600000, // 最大录音时间(毫秒)
  214. sampleRate: 44100,
  215. numberOfChannels: 1,
  216. encodeBitRate: 192000,
  217. format: 'wav',
  218. // frameSize: 50
  219. });
  220. this.isRecording = true;
  221. }
  222. },
  223. // playAudio() {
  224. // if (!this.audioPath) {
  225. // uni.showToast({
  226. // title: '没有可播放的录音',
  227. // icon: 'none'
  228. // });
  229. // return;
  230. // }
  231. // this.innerAudioContext.src = this.audioPath;
  232. // this.innerAudioContext.play();
  233. // },
  234. uploadImagePath() {
  235. let data = {
  236. // name: 'personimage',
  237. // filePath: this.imagePath,
  238. file: this.imagePath
  239. }
  240. uploadPerson(data).then(response => {
  241. store.commit('SET_PERSON', baseUrl + response.data.url)
  242. uni.navigateBack()
  243. })
  244. },
  245. jumpToList() {
  246. let missingFields = [];
  247. if (!this.videoName.trim()) {
  248. missingFields.push('视频名称');
  249. }
  250. // if (!this.fileInfo.path) {
  251. // missingFields.push('人物形象');
  252. // }
  253. if (!this.imagePath) {
  254. missingFields.push('人物形象');
  255. }
  256. // if (!this.modelIndex) {
  257. // missingFields.push('视频模板');
  258. // }
  259. const hasContent = this.videoText.trim() !== '' && this.timbre;
  260. const hasVoice = this.audioPath;
  261. if (!hasContent && !hasVoice) {
  262. missingFields.push('文字内容或语音输入');
  263. }
  264. if (missingFields.length > 0) {
  265. this.missingContent = `请确定:${missingFields.join('、')}是否填写完整!`
  266. this.$refs.alertDialog.open()
  267. return;
  268. }
  269. // this.uploadImagePath()
  270. uni.navigateTo({
  271. url: 'list/creatingVideo/creatingVideo',
  272. });
  273. },
  274. dialogClose() {
  275. console.log('点击关闭')
  276. },
  277. }
  278. }
  279. </script>
  280. <style scoped lang="scss">
  281. .content {
  282. display: flex;
  283. flex-direction: column;
  284. /* align-items: center;
  285. justify-content: center; */
  286. }
  287. .uni-margin-wrap {
  288. width: 690rpx;
  289. width: 100%;
  290. }
  291. .swiper {
  292. height: 300rpx;
  293. }
  294. .swiper-item {
  295. display: block;
  296. height: 300rpx;
  297. line-height: 300rpx;
  298. text-align: center;
  299. background-color: #BD3124;
  300. color: #fff;
  301. }
  302. .form-area {
  303. padding: 20px;
  304. .form-area-item {
  305. display: flex;
  306. flex-direction: row;
  307. margin-top: 30px;
  308. align-items: center;
  309. .form-area-item-text {
  310. width: 120px;
  311. }
  312. /deep/ uni-input {
  313. border: 1px solid #e5e5e5;
  314. border-radius: 4px;
  315. height: 30px;
  316. width: 200px;
  317. }
  318. /deep/ uni-picker {
  319. border-bottom: 1px solid #aaa;
  320. height: 30px;
  321. width: 200px;
  322. display: flex;
  323. align-items: center;
  324. }
  325. /deep/ uni-radio-group,
  326. /deep/ uni-label {
  327. display: flex;
  328. align-items: center;
  329. }
  330. /deep/ uni-label {
  331. margin-right: 10px;
  332. }
  333. /deep/ textarea {
  334. border: 1px solid #aaa;
  335. border-radius: 4px;
  336. width: 320px;
  337. padding: 5px;
  338. margin: 0 auto;
  339. }
  340. .none-file {
  341. margin-left: 10px;
  342. color: #aaa;
  343. }
  344. .file-name {
  345. margin-left: 10px;
  346. width: 50px;
  347. overflow: hidden;
  348. white-space: nowrap;
  349. text-overflow: ellipsis;
  350. }
  351. }
  352. }
  353. .btn-area {
  354. display: flex;
  355. justify-content: center;
  356. margin: 20px auto;
  357. width: 100%;
  358. }
  359. .audio-bar {
  360. text-align: center;
  361. display: block;
  362. margin-top: 10px;
  363. }
  364. /deep/ .uni-border-left{
  365. display:none;
  366. }
  367. </style>