aiCreateVideoDialog.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <el-dialog title="AI生成视频" :visible.sync="dialogVisibleAiCreateVideo" :append-to-body="true" width="700px"
  3. :before-close="handleClose" class="dialog_diy">
  4. <div style="height: 500px;padding:15px" v-loading="loading">
  5. <div style="position: relative; width: 100%;height: 40px;margin-bottom: 10px;">
  6. <el-input class="inputC" style="height: 100%;" placeholder="搜索视频关键字" v-model="detail"
  7. @keyup.enter.native="aiGet()"></el-input>
  8. <div class="search_img" @click="aiGet" style="right: 10px">
  9. <img src="../../../assets/icon/search.png" alt />
  10. </div>
  11. </div>
  12. <div class="Box">
  13. <div class="video_box" v-for="(item,index) in data" :key="index">
  14. <img :src="item.snippet.thumbnails.high.url" />
  15. <span class="name">{{ item.snippet.title }}</span>
  16. <span class="detail">{{ item.snippet.description }}</span>
  17. <div class="btn">
  18. <span @click="openUrl(item.id.videoId)">查看</span>
  19. <span @click="checkUrl(item.snippet.title,item.id.videoId)">加入</span>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. <span slot="footer" class="dialog-footer">
  25. <!-- <el-button @click="aiGet" type="primary">重新生成</el-button> -->
  26. <!-- <el-button @click="confirm" type="primary">确 定</el-button> -->
  27. <el-button @click="close">关 闭</el-button>
  28. </span>
  29. </el-dialog>
  30. </template>
  31. <script>
  32. export default {
  33. components: {
  34. },
  35. props: {
  36. dialogVisibleAiCreateVideo: {
  37. type: Boolean,
  38. default: false
  39. },
  40. courseName: {
  41. type: String,
  42. default: ""
  43. },
  44. },
  45. // 根据用户给你的参考资料
  46. data() {
  47. return {
  48. userid: this.$route.query.userid,
  49. radio: 0,
  50. aiJson: {
  51. ppt: ``,
  52. word: '',
  53. video: ''
  54. },
  55. aiUrl: {
  56. ppt: '',
  57. word: '',
  58. video: ''
  59. },
  60. detail: "",
  61. loading: false,
  62. url: "",
  63. data: [],
  64. uJson: {}
  65. }
  66. },
  67. watch: {
  68. dialogVisibleAiCreateVideo(newValue, oldValue) {
  69. if (newValue) {
  70. // if (this.radio == 0) {
  71. this.detail = this.courseName
  72. // }
  73. // if (this.radio == 1) {
  74. // this.detail = this.aiJson.word
  75. // }
  76. // if (this.radio == 2) {
  77. // this.detail = this.aiJson.video
  78. // }
  79. // this.loading = false
  80. this.aiGet()
  81. }
  82. },
  83. },
  84. methods: {
  85. handleClose(done) {
  86. this.close()
  87. done();
  88. },
  89. close() {
  90. this.$emit('update:dialogVisibleAiCreateVideo', false)
  91. },
  92. openUrl(url){
  93. window.open('https://www.youtube.com/embed/'+url)
  94. },
  95. checkUrl(name,id) {
  96. let json = {
  97. name: "链接",
  98. title: name,
  99. url: 'https://www.youtube.com/embed/'+id,
  100. type: 8,
  101. }
  102. this.$emit('createAiVideo', json)
  103. this.$message.success('加入成功')
  104. },
  105. changeRadio() {
  106. if (this.radio == 0) {
  107. this.detail = this.aiJson.ppt
  108. }
  109. if (this.radio == 1) {
  110. this.detail = this.aiJson.word
  111. }
  112. if (this.radio == 2) {
  113. this.detail = this.aiJson.video
  114. }
  115. },
  116. async aiGet() {
  117. let _this = this
  118. _this.loading = true
  119. this.ajax
  120. .get(`https://www.googleapis.com/youtube/v3/search?key=AIzaSyBUvNQ5Wyua4PbStE2vp3t7MIY4htry-4M&part=snippet&q=${this.detail}&maxResults=10&type=video&order=relevance&regionCode=HK`)
  121. .then((response) => {
  122. console.log(response);
  123. _this.data = response.data.items
  124. _this.loading = false
  125. })
  126. .catch((error) => {
  127. _this.loading = false
  128. console.log(error);
  129. });
  130. },
  131. },
  132. }
  133. </script>
  134. <style scoped>
  135. .dialog_diy>>>.el-dialog {
  136. height: auto;
  137. margin: 15vh auto 0 !important;
  138. }
  139. .dialog_diy>>>.el-dialog__header {
  140. background: #454545 !important;
  141. padding: 15px 20px;
  142. }
  143. .dialog_diy>>>.el-dialog__body {
  144. height: calc(100% - 124px);
  145. box-sizing: border-box;
  146. padding: 0px;
  147. }
  148. .dialog_diy>>>.el-dialog__title {
  149. color: #fff;
  150. }
  151. .dialog_diy>>>.el-dialog__headerbtn {
  152. top: 19px;
  153. }
  154. .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close {
  155. color: #fff;
  156. }
  157. .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close:hover {
  158. color: #fff;
  159. }
  160. .dialog_diy>>>.el-dialog__body,
  161. .dialog_diy>>>.el-dialog__footer {
  162. background: #fafafa;
  163. }
  164. .binfo_input {
  165. width: 100%;
  166. margin: 0;
  167. padding: 5px 7px;
  168. display: block;
  169. min-width: 0;
  170. outline: none;
  171. box-sizing: border-box;
  172. background: none;
  173. border: none;
  174. border-radius: 4px;
  175. background: #fff;
  176. font-size: 15px;
  177. resize: none;
  178. font-family: "Microsoft YaHei";
  179. min-height: 48px;
  180. /* border: 1px solid #3682fc00; */
  181. border: 1.5px solid #cad1dc;
  182. }
  183. .binfo_textarea {
  184. border: 1.5px solid #cad1dc;
  185. font-size: 15px;
  186. resize: none;
  187. /* background: #f6f6f6; */
  188. font-family: "Microsoft YaHei";
  189. }
  190. .binfo_input:focus-visible {
  191. border: 1.5px solid #3681fc !important;
  192. }
  193. .t_box {
  194. display: flex;
  195. margin-bottom: 15px;
  196. }
  197. .t_box>span:nth-child(1) {
  198. min-width: 80px;
  199. font-size: 16px;
  200. color: #000;
  201. }
  202. .inputC >>> .el-input__inner{
  203. padding: '0 35px 0 15px'
  204. }
  205. .search_img {
  206. width: 20px;
  207. height: 20px;
  208. position: absolute;
  209. right: 10px;
  210. top: 50%;
  211. transform: translateY(-50%);
  212. }
  213. .search_img>img {
  214. width: 100%;
  215. height: 100%;
  216. }
  217. .Box{
  218. width: 100%;
  219. height: calc(100% - 50px);
  220. overflow: auto;
  221. display: flex;
  222. flex-direction: row;
  223. justify-content: flex-start;
  224. flex-wrap: wrap;
  225. }
  226. .video_box {
  227. width: calc(100% / 2 - 10px);
  228. /* overflow: hidden; */
  229. margin-right: 10px;
  230. display: flex;
  231. flex-direction: column;
  232. margin-bottom: 15px;
  233. cursor: pointer;
  234. }
  235. .video_box > img{
  236. height: 200px;
  237. object-fit: cover;
  238. }
  239. .video_box > .detail{
  240. color: #cecece;
  241. }
  242. .video_box > .name{
  243. color: #000;
  244. margin: 5px 0;
  245. height: 32px;
  246. }
  247. .btn{
  248. width: 100%;
  249. height: 35px;
  250. display: flex;
  251. align-items: center;
  252. margin-top: auto;
  253. }
  254. .btn > span:hover{
  255. background: #4087f1;
  256. }
  257. .btn > span{
  258. width: 100%;
  259. height: 100%;
  260. background: #3681fc;
  261. color: #fff;
  262. border-radius: 5px;
  263. margin-top: 10px;
  264. cursor: pointer;
  265. display: flex;
  266. align-items: center;
  267. justify-content: center;
  268. }
  269. .btn > span + span{
  270. margin-left: 10px;
  271. }
  272. </style>