details.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="exData.id ? '编辑': '新增'"
  5. :visible.sync="dialog"
  6. width="900px"
  7. :close-on-click-modal="false"
  8. top="50px">
  9. <el-form
  10. ref="form"
  11. :model="form"
  12. :rules="formRules"
  13. label-width="120px">
  14. <el-form-item
  15. prop="video_name"
  16. :rules="formRules.required"
  17. label="视频名称:">
  18. <el-input
  19. v-model="form.video_name"
  20. placeholder="请输入视频名称"
  21. clearable></el-input>
  22. </el-form-item>
  23. <el-form-item
  24. prop="video_introduce"
  25. :rules="formRules.required"
  26. label="视频简介:">
  27. <el-input
  28. type="textarea"
  29. :rows="4"
  30. placeholder="请输入视频简介"
  31. v-model="form.video_introduce">
  32. </el-input>
  33. </el-form-item>
  34. <el-form-item
  35. prop="video_cover_url"
  36. :rules="formRules.uploadImgs"
  37. label="视频封面:">
  38. <el-upload
  39. :on-remove="(file) => {handleRemove(file, 'video_cover_url')}"
  40. :on-success="(file) => {handleAvatarSuccess(file, 'video_cover_url')}"
  41. :before-upload="beforeAvatarUpload"
  42. :on-exceed="hadnleExceed"
  43. :accept="'image/*'"
  44. :limit="1"
  45. :file-list="video_cover_url"
  46. list-type="picture-card"
  47. action="/api/upload/img"
  48. multiple
  49. ref="video_cover_url">
  50. <i class="el-icon-plus"></i>
  51. <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过5M</div>
  52. </el-upload>
  53. </el-form-item>
  54. <el-form-item
  55. prop="video_url"
  56. :rules="formRules.uploadImgs"
  57. label="视频:">
  58. <el-upload
  59. :on-remove="(file) => {handleRemove(file, 'video_url')}"
  60. :on-success="(file) => {handleAvatarSuccess(file, 'video_url')}"
  61. :accept="'video/mp4'"
  62. :limit="1"
  63. :file-list="video_url"
  64. action="/api/upload/img"
  65. :multiple="false"
  66. :show-file-list="false"
  67. ref="video_url">
  68. <el-button
  69. icon="el-icon-plus"
  70. type="text"
  71. slot="trigger"
  72. v-if="form.video_url.length < 1">选择视频
  73. </el-button>
  74. <template v-if="form.video_url.length > 0">
  75. <el-button
  76. icon="el-icon-video-play"
  77. type="text"
  78. slot="tip"
  79. @click="showVideoPlayDialog">视频预览
  80. </el-button>
  81. <el-button
  82. style="margin-left: 20px;"
  83. icon="el-icon-delete"
  84. type="text"
  85. slot="tip"
  86. @click="resetVideoUrl">删除
  87. </el-button>
  88. </template>
  89. </el-upload>
  90. </el-form-item>
  91. <el-form-item
  92. prop="video_auther"
  93. :rules="formRules.required"
  94. label="出镜人员:">
  95. <el-input
  96. type="textarea"
  97. :rows="4"
  98. placeholder="请输入出镜人员"
  99. v-model="form.video_auther">
  100. </el-input>
  101. </el-form-item>
  102. <el-form-item
  103. prop="lunbo_status"
  104. :rules="formRules.select"
  105. label="置顶推荐:">
  106. <el-select
  107. style="width: 100%;"
  108. v-model="form.lunbo_status"
  109. filterable
  110. clearable
  111. placeholder="请选择是否置顶推荐">
  112. <el-option
  113. :label="item.name"
  114. :value="item.value"
  115. v-for="item in arrRecommend"
  116. :key="item.value"></el-option>
  117. </el-select>
  118. </el-form-item>
  119. <el-form-item
  120. prop="video_status"
  121. :rules="formRules.select"
  122. label="状态:">
  123. <el-select
  124. style="width: 100%;"
  125. v-model="form.video_status"
  126. filterable
  127. clearable
  128. placeholder="请选择状态">
  129. <el-option
  130. :label="item.name"
  131. :value="item.value"
  132. v-for="item in arrHideAndShow"
  133. :key="item.value"></el-option>
  134. </el-select>
  135. </el-form-item>
  136. </el-form>
  137. <div slot="footer" class="dialog-footer text-center">
  138. <el-button @click="dialog = false">取 消</el-button>
  139. <el-button
  140. type="primary"
  141. :disabled="booLock"
  142. @click="handleSubmit">确 定
  143. </el-button>
  144. </div>
  145. </el-dialog>
  146. </div>
  147. </template>
  148. <script>
  149. export default {
  150. props: {
  151. value: {
  152. type: Boolean,
  153. default: true
  154. },
  155. exData: {
  156. type: Object,
  157. default: function () {
  158. return {}
  159. }
  160. },
  161. arrRecommend: {
  162. type: Array,
  163. default: function () {
  164. return []
  165. }
  166. },
  167. arrHideAndShow: {
  168. type: Array,
  169. default: function () {
  170. return []
  171. }
  172. }
  173. },
  174. data() {
  175. return {
  176. dialog: !!this.value,
  177. form: {
  178. 'video_name': '', // 视频名称
  179. 'video_introduce': '', // 视频简介
  180. 'video_cover_url': [], // 封面地址
  181. 'video_url': [], // 视频地址
  182. 'video_auther': '', // 出境人
  183. 'lunbo_status': '0', // 置顶推荐(0否1是)
  184. 'video_status': '0' // 视频状态 0隐藏 1显示
  185. },
  186. video_cover_url: [],
  187. video_url: [],
  188. booLock: false
  189. }
  190. },
  191. methods: {
  192. beforeAvatarUpload(file) {
  193. const isLt2M = file.size / 1024 / 1024 < 5
  194. if (!isLt2M) {
  195. this.$message.error('上传图片大小不能超过 5MB!')
  196. }
  197. return isLt2M
  198. },
  199. hadnleExceed(files, fileList) {
  200. this.$message({
  201. message: '最多上传一张',
  202. type: 'warning'
  203. })
  204. },
  205. handleRemove(file, formKey) {
  206. let path = file.url
  207. if (file.response && file.response.data) {
  208. path = file.response.data.path
  209. }
  210. this.form[formKey] = this.form[formKey].filter(item => item !== path)
  211. },
  212. handleAvatarSuccess(res, formKey) {
  213. if (res.code === 200) {
  214. const { path } = res.data
  215. this.form[formKey].push(path)
  216. } else {
  217. this.$message.error('图片上传失败')
  218. }
  219. },
  220. handleSubmit() {
  221. const url = this.exData.id ? '/api/admin/video/modify' : '/api/admin/video/add'
  222. this.$refs.form.validate(async valid => {
  223. if (valid) {
  224. const formData = JSON.parse(JSON.stringify(this.form))
  225. const postData = {
  226. ...formData,
  227. video_cover_url: formData.video_cover_url[0],
  228. video_url: formData.video_url[0]
  229. }
  230. this.booLock = true
  231. const data = await this.$fetch(url, postData)
  232. this.booLock = false
  233. if (data.code === 200) {
  234. this.$message.success('提交成功')
  235. this.$emit('success')
  236. this.dialog = false
  237. }
  238. }
  239. })
  240. },
  241. showVideoPlayDialog() {
  242. this.$store.commit('common/SET_VIDEOPLAYDIALOG', {
  243. src: this.form.video_url[0],
  244. show: true
  245. })
  246. },
  247. resetVideoUrl() {
  248. this.form.video_url.splice(0, 1)
  249. this.video_url.splice(0, 1)
  250. }
  251. },
  252. mounted() {
  253. if (this.exData.id) {
  254. this.$set(this.form, 'id', this.exData.id)
  255. this.video_cover_url = [
  256. {
  257. name: '',
  258. url: this.exData.video_cover_url
  259. }
  260. ]
  261. this.video_url = [
  262. {
  263. name: '',
  264. url: this.exData.video_url
  265. }
  266. ]
  267. for (const key in this.exData) {
  268. if (this.form.hasOwnProperty(key)) {
  269. let value = this.exData[key]
  270. if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
  271. if (key === 'video_cover_url' || key === 'video_url') {
  272. value = [value]
  273. }
  274. if (key === 'lunbo_status' || key === 'video_status') {
  275. value = value + ''
  276. }
  277. this.$set(this.form, key, value)
  278. }
  279. }
  280. }
  281. }
  282. },
  283. watch: {
  284. dialog(val) {
  285. if (!val) this.$emit('input', val)
  286. }
  287. }
  288. }
  289. </script>
  290. <style lang="scss" scoped>
  291. .top-tip {
  292. margin-top: -20px;
  293. margin-bottom: 20px;
  294. }
  295. .af-put-line-radio {
  296. display: flex;
  297. align-items: center;
  298. p.lalel {
  299. padding: 0 10px;
  300. }
  301. p {
  302. padding: 0;
  303. margin: 0;
  304. }
  305. }
  306. </style>