index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <schema-table
  9. ref="table"
  10. :schema="schema"
  11. />
  12. <confirm-dialog
  13. ref="editDialog"
  14. :title="isEdit ? '编辑' : '新增'"
  15. @confirm="onSave"
  16. >
  17. <div class="c-grid-form u-align-self--center">
  18. <span class="c-grid-form__label u-required">
  19. 名称
  20. </span>
  21. <el-input
  22. v-model.trim="selfFrom.name"
  23. placeholder="最多30个字符"
  24. maxlength="30"
  25. clearable
  26. />
  27. <span class="c-grid-form__label">
  28. 备注
  29. </span>
  30. <el-input
  31. v-model.trim="selfFrom.remark"
  32. type="textarea"
  33. maxlength="100"
  34. :rows="4"
  35. resize="none"
  36. show-word-limit
  37. />
  38. </div>
  39. </confirm-dialog>
  40. <confirm-dialog
  41. ref="uploadDialog"
  42. title="新增导入文件"
  43. @confirm="onUpload"
  44. >
  45. <el-upload
  46. ref="upload"
  47. class="o-upload l-flex__auto"
  48. action="none"
  49. :auto-upload="false"
  50. :show-file-list="false"
  51. :on-change="onChange"
  52. accept=".xlsx"
  53. drag
  54. >
  55. <div class="l-flex--row">
  56. <i class="o-upload__icon el-icon-upload" />
  57. <template v-if="upload.file">
  58. <div class="u-color--blue">
  59. {{ upload.file.name }}
  60. </div>
  61. </template>
  62. <template v-else>
  63. <span class="c-sibling-item">
  64. 拖拽文件到此或
  65. </span>
  66. <span class="c-sibling-item near u-color--blue">
  67. 点击选择文件
  68. </span>
  69. </template>
  70. </div>
  71. </el-upload>
  72. </confirm-dialog>
  73. <el-dialog
  74. :visible.sync="showProgress"
  75. custom-class="c-dialog--transparent"
  76. :close-on-click-modal="false"
  77. :close-on-press-escape="false"
  78. >
  79. <el-progress
  80. class="u-align-self--stretch"
  81. :percentage="progress"
  82. :stroke-width="24"
  83. text-inside
  84. status="success"
  85. />
  86. </el-dialog>
  87. </wrapper>
  88. </template>
  89. <script>
  90. import {
  91. getSelfByAdvertisingQuery,
  92. addSelf,
  93. updateSelf,
  94. deleteSelf,
  95. uploadSelf
  96. } from '@/api/unified.js'
  97. export default {
  98. data () {
  99. return {
  100. upload: {},
  101. showProgress: false,
  102. progress: 0,
  103. selfFrom: {},
  104. isEdit: false
  105. }
  106. },
  107. computed: {
  108. schema () {
  109. return {
  110. props: {
  111. size: 'small'
  112. },
  113. list: getSelfByAdvertisingQuery,
  114. buttons: [
  115. { type: 'add', on: this.onAdd },
  116. { type: 'add', label: '上传', on: this.uploadStreamingMedia }
  117. ],
  118. filters: [
  119. { key: 'name', type: 'search', placeholder: '广告名称' },
  120. { type: 'refresh' }
  121. ],
  122. cols: [
  123. { prop: 'name', label: '广告名称' },
  124. {
  125. prop: 'status',
  126. label: '状态',
  127. render: (data, h) => h('el-switch', {
  128. props: {
  129. value: data.status,
  130. size: 'mini',
  131. 'active-value': 1,
  132. 'active-color': '#13ce66',
  133. 'inactive-value': 0,
  134. 'inactive-color': '#ff4949'
  135. },
  136. // nativeOn: {
  137. // click: e => e.stopPropagation()
  138. // },
  139. nativeOn: {
  140. click: val => {
  141. this.onStatus(data, val)
  142. }
  143. }
  144. }),
  145. width: 72,
  146. align: 'center'
  147. },
  148. { prop: 'remark', label: '备注' },
  149. {
  150. type: 'invoke',
  151. render: [
  152. { label: '编辑', on: this.onView },
  153. { label: '删除', on: this.onDel }
  154. ],
  155. width: 100
  156. }
  157. ]
  158. }
  159. }
  160. },
  161. methods: {
  162. onStatus (asset) {
  163. updateSelf({
  164. id: asset.id,
  165. name: asset.name,
  166. remark: asset.remark,
  167. status: asset.status === 1 ? 0 : 1
  168. })
  169. .then(() => {
  170. asset.status = asset.status === 1 ? 0 : 1
  171. })
  172. .catch(() => {})
  173. },
  174. onAdd () {
  175. this.isEdit = false
  176. this.selfFrom = {
  177. name: '',
  178. remark: ''
  179. }
  180. this.$refs.editDialog.show()
  181. },
  182. onView (asset) {
  183. this.isEdit = true
  184. this.selfFrom = {
  185. id: asset.id,
  186. name: asset.name,
  187. remark: asset.remark
  188. }
  189. this.$refs.editDialog.show()
  190. },
  191. onSave (done) {
  192. const { name } = this.selfFrom
  193. if (!name) {
  194. this.$message({
  195. type: 'warning',
  196. message: '请填写广告名称'
  197. })
  198. return
  199. }
  200. (this.isEdit ? updateSelf : addSelf)(this.selfFrom).then(() => {
  201. done()
  202. this.$refs.table.pageTo(1)
  203. })
  204. },
  205. onDel (asset) {
  206. deleteSelf(asset).then(() => {
  207. this.$refs.table.decrease(1)
  208. })
  209. },
  210. uploadStreamingMedia () {
  211. this.upload = {
  212. file: null
  213. }
  214. this.$refs.uploadDialog.show()
  215. },
  216. onUpload (done) {
  217. if (!this.upload.file) {
  218. this.$message({
  219. type: 'warning',
  220. message: '请选择上传文件'
  221. })
  222. return
  223. }
  224. const formData = new FormData()
  225. const { file } = this.upload
  226. console.log(file)
  227. formData.append('upload-file', file)
  228. this.progress = 0
  229. this.showProgress = true
  230. uploadSelf(formData, ({ loaded, total }) => {
  231. this.progress = Math.min(99, ((loaded * 100) / total) | 0)
  232. })
  233. .finally(() => {
  234. this.progress = 100
  235. this.showProgress = false
  236. })
  237. .then(() => {
  238. done()
  239. this.$refs.table.resetCondition()
  240. })
  241. },
  242. onChange ({ raw }) {
  243. this.$refs.upload.clearFiles()
  244. this.upload.file = raw
  245. },
  246. onAdded (streamingMedia) {
  247. this.$refs.table.resetCondition(streamingMedia)
  248. }
  249. }
  250. }
  251. </script>