Tab5DialogThree.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div class="Tab5DialogThree">
  3. <el-dialog
  4. :title="ruleForm.id ? '修改' : '新增'"
  5. :visible="isShow"
  6. @close="btnX()"
  7. >
  8. <el-form
  9. :model="ruleForm"
  10. :rules="rules"
  11. ref="ruleForm"
  12. label-width="100px"
  13. class="demo-ruleForm"
  14. >
  15. <el-form-item label="年份:" prop="year">
  16. <el-input v-model="ruleForm.year" style="width:500px"></el-input>
  17. </el-form-item>
  18. <!-- 图片和附件 -->
  19. <el-form-item label="进度图片:">
  20. <i class="biaoshi"></i>
  21. <el-upload
  22. class="avatar-uploader"
  23. :action="baseURL + '/cms/site/img/upload'"
  24. :headers="{
  25. token,
  26. }"
  27. :show-file-list="false"
  28. :before-upload="beforethumbUpload"
  29. :on-success="upload_thumb_success"
  30. >
  31. <div v-if="ruleForm.thumb" class="imgdiv">
  32. <img
  33. style="width: 100%; height: 100%"
  34. :src="baseURL + ruleForm.thumb"
  35. />
  36. <i
  37. class="el-icon-circle-close"
  38. @click.stop="ruleForm.thumb = ''"
  39. ></i>
  40. </div>
  41. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  42. </el-upload>
  43. <span>格式要求:支持png、jpg、gif和jpeg的图片格式;最大支持5M。</span>
  44. </el-form-item>
  45. </el-form>
  46. <div slot="footer" class="dialog-footer">
  47. <el-button @click="btnX">取 消</el-button>
  48. <el-button type="primary" @click="btnOk">确 定</el-button>
  49. </div>
  50. </el-dialog>
  51. </div>
  52. </template>
  53. <script>
  54. import { videoDetailById3, siteImgSave } from '@/apis/tab5'
  55. import axios from '@/utils/request'
  56. export default {
  57. name: 'Tab5DialogThree',
  58. props: {
  59. isShow: {
  60. type: Boolean,
  61. default: false
  62. }
  63. },
  64. components: {},
  65. data () {
  66. return {
  67. // 服务器前缀地址
  68. baseURL: '',
  69. token: '',
  70. ruleForm: {
  71. id: '',
  72. thumb: '',
  73. year: ''
  74. },
  75. rules: {
  76. year: [{ required: true, message: '不能为空', trigger: 'blur' }]
  77. }
  78. }
  79. },
  80. computed: {},
  81. watch: {
  82. },
  83. methods: {
  84. // 点击关闭
  85. btnX () {
  86. this.$emit('update:isShow', false)
  87. // 清空表单
  88. this.ruleForm = {
  89. id: '',
  90. thumb: '',
  91. year: ''
  92. }
  93. // 关闭验证
  94. this.$refs.ruleForm.resetFields()
  95. },
  96. // 点击确定
  97. async btnOk () {
  98. if (this.ruleForm.thumb === '') { return this.$message.warning('封面图片不能为空') }
  99. if (this.ruleForm.year.trim() === '') { return this.$message.warning('年份不能为空') }
  100. const obj = { ...this.ruleForm }
  101. const res = await siteImgSave(obj)
  102. if (res.code === 0) {
  103. this.$message.success('操作成功')
  104. // 通知父组件刷新页面
  105. this.$emit('refresh')
  106. this.btnX()
  107. } else return this.$message.warning(res.msg)
  108. // console.log(998, res)
  109. },
  110. // 上传图片
  111. beforethumbUpload (file) {
  112. // console.log(998, file)
  113. // 限制图片大小和格式
  114. const sizeOk = file.size / 1024 / 1024 < 5
  115. const typeOk =
  116. file.type === 'image/png' ||
  117. (file.type === 'image/jpeg' && !file.name.includes('.jfif')) ||
  118. file.type === 'image/gif'
  119. return new Promise((resolve, reject) => {
  120. if (!typeOk) {
  121. this.$message.error('照片格式有误!')
  122. reject(file)
  123. } else if (!sizeOk) {
  124. this.$message.error('照片大小超过5M!')
  125. reject(file)
  126. } else if (file.name.length > 32) {
  127. this.$message.error('照片名字不能超过32个字!')
  128. reject(file)
  129. } else {
  130. this.$message.success('上传成功')
  131. resolve(file)
  132. }
  133. })
  134. },
  135. upload_thumb_success (data) {
  136. // console.log('图片上传成功', data.data.urlPath)
  137. this.ruleForm.thumb = data.data.urlPath
  138. },
  139. // 通过id获取详情---让父组件调用
  140. async videoDetailById3 (id) {
  141. const res = await videoDetailById3(id)
  142. this.ruleForm = res.data
  143. // console.log(998, res)
  144. }
  145. },
  146. // 生命周期 - 创建完成(可以访问当前this实例)
  147. created () {
  148. // 获取服务器前缀地址
  149. this.baseURL = axios.defaults.baseURL
  150. // 获取用户token
  151. this.token = localStorage.getItem('CQLJXU_token')
  152. },
  153. // 生命周期 - 挂载完成(可以访问DOM元素)
  154. mounted () {},
  155. beforeCreate () {}, // 生命周期 - 创建之前
  156. beforeMount () {}, // 生命周期 - 挂载之前
  157. beforeUpdate () {}, // 生命周期 - 更新之前
  158. updated () {}, // 生命周期 - 更新之后
  159. beforeDestroy () {}, // 生命周期 - 销毁之前
  160. destroyed () {}, // 生命周期 - 销毁完成
  161. activated () {} // 如果页面有keep-alive缓存功能,这个函数会触发
  162. }
  163. </script>
  164. <style lang='less' scoped>
  165. .biaoshi::before {
  166. top: 1px;
  167. }
  168. .biaoshi2::before {
  169. top: -10px;
  170. left: -64px;
  171. }
  172. /deep/.el-upload-list {
  173. width: 500px;
  174. }
  175. /deep/.el-icon-plus {
  176. border: 1px dashed #ccc;
  177. }
  178. .avatar-uploader .el-upload {
  179. border-radius: 6px;
  180. cursor: pointer;
  181. position: relative;
  182. overflow: hidden;
  183. }
  184. .avatar-uploader .el-upload:hover {
  185. border-color: #3e5eb3;
  186. }
  187. .avatar-uploader-icon {
  188. font-size: 28px;
  189. color: #8c939d;
  190. width: 178px;
  191. height: 178px;
  192. line-height: 178px;
  193. text-align: center;
  194. }
  195. /deep/.el-icon-circle-close {
  196. font-size: 20px;
  197. }
  198. .imgdiv {
  199. max-width: 400px;
  200. }
  201. </style>