advertising.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <el-card shadow="never" class="aui-card--fill">
  3. <div class="mod-home">
  4. <div class="page-title">{{ title }}</div>
  5. <div class="btns adf">
  6. <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增广告位</el-button>
  7. </div>
  8. </div>
  9. <el-table :data="dataList" border cell-class-name="vertical-top-cell" v-loading="loading" empty-text="暂无广告" max-height="578px" style="margin-top: 18px;">
  10. <el-table-column label="序号" width="50">
  11. <template #default="scope">
  12. {{ scope.$index + 1 }}
  13. </template>
  14. </el-table-column>
  15. <el-table-column label="广告位位置" prop="space">
  16. <template #default="{ row }">{{ spaceCfg[row.space]||'' }}</template>
  17. </el-table-column>
  18. <el-table-column label="图片" prop="fileUrl">
  19. <template #default="{ row }">
  20. <img :src="row.fileUrl" v-if="row.fileUrl" style="width: 130px;height: auto;" @click="showBigImg(row.fileUrl)">
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="广告位标题" prop="title"></el-table-column>
  24. <el-table-column label="跳转链接" prop="redirect"></el-table-column>
  25. <!-- <el-table-column label="点击量" prop="xx"></el-table-column> -->
  26. <el-table-column label="创建时间" prop="createDate"></el-table-column>
  27. <el-table-column label="上架状态" prop="enable">
  28. <template #default="{ row }">
  29. <el-switch v-model="row.enable" active-color="#33A7A7" inactive-color="#B9C0C8" @change="e=>statusChange(e,row)"></el-switch>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="操作" width="200">
  33. <template #default="scope">
  34. <el-button link type="text" size="mini" @click="handleEdit(scope.row)">编辑</el-button>
  35. <el-button link type="text" size="mini" @click="handleDelete(scope.row)">删除</el-button>
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. <el-pagination
  40. @size-change="handleSizeChange"
  41. @current-change="handleCurrentChange"
  42. :current-page="queryParams.page"
  43. :page-sizes="[5, 10, 20, 50]"
  44. :page-size="10"
  45. layout="total, sizes, prev, pager, next, jumper"
  46. :total="total"
  47. v-show="total > 0">
  48. </el-pagination>
  49. <el-dialog width="40%" :visible.sync="show" :title="dialogTitle" @close="cancel">
  50. <el-form ref="advertRef" :model="advertForm" :rules="advertRules" label-width="100px" style="width: 90%;margin: 0 auto;">
  51. <el-form-item label="广告位位置" prop="space">
  52. <el-select v-model="advertForm.space" placeholder="请选择广告位位置" style="width:100%">
  53. <el-option label="首页" :value="1"></el-option>
  54. <el-option label="发布问卷" :value="2"></el-option>
  55. </el-select>
  56. </el-form-item>
  57. <!-- <el-form-item label="广告位类型" prop="type">
  58. <el-select v-model="advertForm.type" placeholder="请选择广告位类型" style="width:100%">
  59. <el-option label="banner区" :value="1"></el-option>
  60. <el-option label="弹框" :value="2"></el-option>
  61. </el-select>
  62. </el-form-item> -->
  63. <el-form-item label="广告位标题" prop="title">
  64. <el-input v-model="advertForm.title" placeholder="请输入广告位标题"></el-input>
  65. </el-form-item>
  66. <el-form-item label="配图" prop="" class="red">
  67. <el-upload
  68. list-type="picture-card"
  69. :action="uploadUrl"
  70. :headers="uploadHeaders"
  71. :on-success="uploadFileSuccess"
  72. :on-remove="removeFile"
  73. :before-upload="beforeAvatarUpload"
  74. :limit="1"
  75. :file-list="fileList">
  76. <i class="el-icon-plus"></i>
  77. </el-upload>
  78. <div class="dialog-tip">图片最小分辨率:702*200</div>
  79. </el-form-item>
  80. <el-form-item label="跳转链接" prop="redirectType">
  81. <el-radio-group v-model="advertForm.redirectType">
  82. <el-radio :label="1">微信公众号</el-radio>
  83. <el-radio :label="2">微信小程序</el-radio>
  84. </el-radio-group>
  85. <el-input v-model="advertForm.redirect" placeholder="配置跳转链接"></el-input>
  86. </el-form-item>
  87. </el-form>
  88. <div class="demo-drawer__footer" style="display: flex;justify-content: end;">
  89. <el-button :loading="buttonLoading" type="primary" @click="submitForm">保 存</el-button>
  90. <el-button @click="cancel" style="margin-right: 5%;">取 消</el-button>
  91. </div>
  92. </el-dialog>
  93. <el-dialog width="40%" :visible.sync="bigShow" title="广告位图片" @close="bigShow=false">
  94. <img :src="bigImg" style="width: 100%;height: auto;">
  95. <div class="demo-drawer__footer" style="display: flex;justify-content: end;margin-top: 50px;">
  96. <el-button @click="bigShow=false" style="margin-right: 5%;">关 闭</el-button>
  97. </div>
  98. </el-dialog>
  99. </el-card>
  100. </template>
  101. <script>
  102. import Cookies from 'js-cookie'
  103. export default {
  104. data () {
  105. return {
  106. title: this.$route.meta.title,
  107. uploadUrl: `${window.SITE_CONFIG['apiURL']}/sys/oss/uploadFile`,
  108. uploadHeaders: { token: Cookies.get('token') },
  109. fileList: [],
  110. queryParams: {
  111. page: 1,
  112. limit: 10
  113. },
  114. spaceCfg: {
  115. '1': '首页',
  116. '2': '发布问卷'
  117. },
  118. typeCfg: {
  119. '1': 'banner区',
  120. '2': '弹框'
  121. },
  122. dataList: [],
  123. total: 0,
  124. loading: false,
  125. buttonLoading: false,
  126. show: false,
  127. bigShow: false,
  128. bigImg: '',
  129. dialogTitle: '新增广告位',
  130. advertForm: {
  131. id: '',
  132. space: '',
  133. type: '',
  134. title: '',
  135. redirectType: 1,
  136. redirect: '',
  137. fileUrl: '',
  138. enable: 1
  139. },
  140. advertRules: {
  141. space: [
  142. { required: true, message: '请选择广告位位置', trigger: 'change' }
  143. ],
  144. title: [
  145. { required: true, message: '请输入广告位标题', trigger: 'blur' }
  146. ]
  147. }
  148. }
  149. },
  150. mounted () {
  151. this.getList()
  152. },
  153. methods: {
  154. getList () {
  155. this.loading = true
  156. this.$http.get('/core/advertisement/manage/page', { params: this.queryParams }).then(res => {
  157. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  158. this.dataList = res.data.data.list
  159. this.dataList.forEach(item => {
  160. // eslint-disable-next-line no-unneeded-ternary
  161. item.enable = item.enable === 1 ? true : false
  162. })
  163. this.total = res.data.data.total
  164. this.loading = false
  165. })
  166. },
  167. handleSizeChange (e) {
  168. this.queryParams.limit = e
  169. this.getList()
  170. },
  171. handleCurrentChange (e) {
  172. this.queryParams.page = e
  173. this.getList()
  174. },
  175. handleAdd () {
  176. this.dialogTitle = '新增广告位'
  177. this.show = true
  178. },
  179. handleEdit (row) {
  180. this.dialogTitle = '编辑广告位'
  181. this.$http.get(`/core/advertisement/manage/${row.id}`).then(res => {
  182. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  183. this.advertForm = { ...this.advertForm, ...res.data.data }
  184. this.fileList = [{ name: '', url: this.advertForm.fileUrl }]
  185. this.show = true
  186. })
  187. },
  188. submitForm () {
  189. this.$refs['advertRef'].validate((valid) => {
  190. if (valid) {
  191. if (this.fileList.length === 0) return this.$message.error('请上传图片')
  192. this.advertForm.fileUrl = this.fileList[0].url
  193. this.$http[this.advertForm.id ? 'put' : 'post']('/core/advertisement/manage', this.advertForm).then(res => {
  194. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  195. this.$message.success('保存成功')
  196. this.cancel()
  197. this.getList()
  198. })
  199. } else {
  200. return false
  201. }
  202. })
  203. },
  204. cancel () {
  205. this.advertForm = {
  206. id: '',
  207. space: '',
  208. type: '',
  209. title: '',
  210. redirectType: 1,
  211. redirect: '',
  212. fileUrl: '',
  213. enable: 1
  214. }
  215. this.$refs['advertRef'].resetFields()
  216. this.show = false
  217. },
  218. handleDelete (row) {
  219. this.$confirm(`确认删除该广告位吗?`, '提示', {
  220. type: 'warning'
  221. }).then(() => {
  222. this.$http.delete('/core/advertisement/manage', { 'data': [row.id] }).then(res => {
  223. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  224. this.$message.success('删除成功')
  225. this.getList()
  226. })
  227. })
  228. },
  229. statusChange (e, row) {
  230. let data = JSON.parse(JSON.stringify(row))
  231. data.enable = data.enable ? 1 : 0
  232. this.$http.put('/core/advertisement/manage', data).then(res => {
  233. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  234. this.getList()
  235. })
  236. },
  237. uploadFileSuccess (e) {
  238. if (e.data) {
  239. this.fileList.unshift({ name: '', url: e.data })
  240. }
  241. },
  242. removeFile (e) {
  243. this.fileList = []
  244. this.advertForm.fileUrl = ''
  245. },
  246. beforeAvatarUpload (file) {
  247. // if (!['image/jpeg', 'image/png', 'image/jpg'].includes(file.type)) {
  248. // return proxy.$message.error('上传图片只能是 JPG/PNG/JPEG 格式!');
  249. // }
  250. // if (file.size / 1024 / 1024 > 5) {
  251. // return proxy.$message.error('上传图片大小不能超过 5MB!');
  252. // }
  253. return true
  254. },
  255. showBigImg (imgurl) {
  256. this.bigImg = imgurl
  257. this.bigShow = true
  258. }
  259. }
  260. }
  261. </script>
  262. <style scoped lang="scss">
  263. .page-title{
  264. font-family: PingFang-SC, PingFang-SC;
  265. font-weight: bold;
  266. font-size: 16px;
  267. color: #252525;
  268. line-height: 22px;
  269. }
  270. .btns{
  271. justify-content: flex-end;
  272. margin-top: -10px;
  273. }
  274. </style>