index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <!-- <el-form-item label="轮播图类型" prop="bannerType" label-width="120px">-->
  5. <!-- <el-select v-model="queryParams.bannerType" placeholder="轮播图类型" clearable>-->
  6. <!-- <el-option-->
  7. <!-- v-for="dict in dict.type.app_banner_type"-->
  8. <!-- :key="dict.value"-->
  9. <!-- :label="dict.label"-->
  10. <!-- :value="dict.value"-->
  11. <!-- />-->
  12. <!-- </el-select>-->
  13. <!-- </el-form-item>-->
  14. <!-- <el-form-item label="点击类型" prop="clickType">-->
  15. <!-- <el-select v-model="queryParams.clickType" placeholder="点击类型" clearable>-->
  16. <!-- <el-option-->
  17. <!-- v-for="dict in dict.type.app_banner_click_type"-->
  18. <!-- :key="dict.value"-->
  19. <!-- :label="dict.label"-->
  20. <!-- :value="dict.value"-->
  21. <!-- />-->
  22. <!-- </el-select>-->
  23. <!-- </el-form-item>-->
  24. <el-form-item prop="status">
  25. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
  26. <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item>
  30. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  31. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  32. </el-form-item>
  33. </el-form>
  34. <el-row :gutter="10" class="mb8">
  35. <el-col :span="1.5">
  36. <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd" v-hasPermi="[bannerType == 0 ? 'app:banner:add' : 'app:launchAdver:add']">新增</el-button>
  37. </el-col>
  38. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  39. </el-row>
  40. <Page uri="/app/banner/list" :request-params="queryParams" ref="pagination">
  41. <el-table-column label="ID" align="center" prop="id" />
  42. <el-table-column label="图片" align="center" prop="imgUrl" width="100">
  43. <template slot-scope="scope">
  44. <el-image style="width: 80px; height: 80px" :src="scope.row.imgUrl" :preview-src-list="[scope.row.imgUrl]"> </el-image>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="图片类型" align="center" prop="bannerType">
  48. <template slot-scope="scope">
  49. <dict-tag :options="dict.type.app_banner_type" :value="scope.row.bannerType" />
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="点击类型" align="center" prop="clickType">
  53. <template slot-scope="scope">
  54. <dict-tag :options="dict.type.app_banner_click_type" :value="scope.row.clickType" />
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="启用状态" align="center" prop="status">
  58. <template slot-scope="scope">
  59. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status" />
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="创建人" align="center" prop="createBy" />
  63. <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
  64. <el-table-column label="修改人" align="center" prop="updateBy" />
  65. <el-table-column label="修改时间" align="center" prop="createTime" width="180" />
  66. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  67. <template slot-scope="scope">
  68. <el-button type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="[bannerType == 0 ? 'app:banner:edit' : 'app:launchAdver:edit']">修改</el-button>
  69. <el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="[bannerType == 0 ? 'app:banner:remove' : 'app:launchAdver:remove']">删除</el-button>
  70. </template>
  71. </el-table-column>
  72. </Page>
  73. <!-- 添加或修改轮播图对话框 -->
  74. <el-dialog :title="title" :visible.sync="open" size="30%" append-to-body>
  75. <el-row :gutter="15">
  76. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  77. <el-col :span="24">
  78. <el-form-item label="上传" prop="imgUrl">
  79. <el-upload class="image-uploader" :action="uploadAction" :before-upload="handleBeforeUpload" :on-success="handleUploadSuccess" :on-error="handleUploadError" accept="image/*" :show-file-list="false">
  80. <img v-if="form.imgUrl" :src="form.imgUrl" />
  81. <i v-else class="el-icon-plus image-uploader-icon"></i>
  82. </el-upload>
  83. </el-form-item>
  84. </el-col>
  85. <!-- <el-col :span="24">-->
  86. <!-- <el-form-item label="轮播图类型" prop="bannerType">-->
  87. <!-- <el-radio-group v-model="form.bannerType" size="small">-->
  88. <!-- <el-radio-button v-for="dict in dict.type.app_banner_type" :label="dict.value">{{dict.label}}</el-radio-button>-->
  89. <!-- </el-radio-group>-->
  90. <!-- </el-form-item>-->
  91. <!-- </el-col>-->
  92. <el-col :span="24">
  93. <el-form-item label="点击类型" prop="clickType">
  94. <el-radio-group v-model="form.clickType" size="small" @input="onClickTypeChange">
  95. <el-radio-button v-for="dict in dict.type.app_banner_click_type" :label="dict.value">{{ dict.label }}</el-radio-button>
  96. </el-radio-group>
  97. </el-form-item>
  98. </el-col>
  99. <el-col :span="24" v-if="form.clickType == '1'">
  100. <el-form-item label="跳转内容" prop="redirectContent">
  101. <el-input v-model="form.redirectContent" placeholder="请输入跳转网址" />
  102. </el-form-item>
  103. </el-col>
  104. <el-col :span="24" v-if="form.clickType == '2'">
  105. <el-form-item label="跳转内容" prop="redirectContent">
  106. <editor v-model="form.redirectContent" :min-height="192" />
  107. </el-form-item>
  108. </el-col>
  109. <el-col :span="24">
  110. <el-form-item label="状态" prop="status">
  111. <el-radio-group v-model="form.status" size="small">
  112. <el-radio-button v-for="dict in dict.type.sys_normal_disable" :label="dict.value">{{ dict.label }}</el-radio-button>
  113. </el-radio-group>
  114. </el-form-item>
  115. </el-col>
  116. </el-form>
  117. </el-row>
  118. <div slot="footer" class="dialog-footer">
  119. <el-button type="primary" @click="submitForm" style="margin-left: 5%">提交</el-button>
  120. <el-button @click="cancel">取 消</el-button>
  121. </div>
  122. </el-dialog>
  123. </div>
  124. </template>
  125. <script>
  126. import { listBanner, getBanner, delBanner, addBanner, updateBanner } from '@/api/app/banner'
  127. export default {
  128. name: 'Banner',
  129. dicts: ['app_banner_type', 'app_banner_click_type', 'sys_normal_disable'],
  130. data() {
  131. return {
  132. uploadAction: `${process.env.VUE_APP_BASE_API}` + '/common/uploadOSS',
  133. // 遮罩层
  134. loading: true,
  135. // 选中数组
  136. ids: [],
  137. // 非单个禁用
  138. single: true,
  139. // 非多个禁用
  140. multiple: true,
  141. // 显示搜索条件
  142. showSearch: true,
  143. // 总条数
  144. total: 0,
  145. // 轮播图表格数据
  146. bannerList: [],
  147. // 弹出层标题
  148. title: '',
  149. // 是否显示弹出层
  150. open: false,
  151. // 查询参数
  152. queryParams: {
  153. bannerType: null,
  154. imgUrl: null,
  155. clickType: null,
  156. redirectContent: null,
  157. status: null,
  158. createById: null,
  159. updateById: null
  160. },
  161. // 表单参数
  162. form: {},
  163. // 表单校验
  164. rules: {
  165. bannerType: [
  166. {
  167. required: true,
  168. message: '图片类型不能为空',
  169. trigger: 'blur'
  170. }
  171. ],
  172. imgUrl: [
  173. {
  174. required: true,
  175. message: '请先上传图片',
  176. trigger: 'blur'
  177. }
  178. ],
  179. clickType: [
  180. {
  181. required: true,
  182. message: '点击类型不能为空',
  183. trigger: 'blur'
  184. }
  185. ],
  186. status: [
  187. {
  188. required: true,
  189. message: '状态不能为空',
  190. trigger: 'blur'
  191. }
  192. ],
  193. redirectContent: [
  194. {
  195. required: true,
  196. message: '跳转内容不能为空',
  197. trigger: 'blur'
  198. }
  199. ]
  200. },
  201. bannerType: ''
  202. }
  203. },
  204. created() {
  205. this.bannerType = this.getUrlParam('bannerType')
  206. this.queryParams.bannerType = this.bannerType
  207. this.form.bannerType = this.bannerType
  208. this.getList()
  209. },
  210. methods: {
  211. onClickTypeChange() {
  212. this.form.redirectContent = ''
  213. },
  214. // 上传前校检格式和大小
  215. handleBeforeUpload(file) {
  216. // 校检文件大小
  217. if (this.fileSize) {
  218. const isLt = file.size / 1024 / 1024 < this.fileSize
  219. if (!isLt) {
  220. this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`)
  221. return false
  222. }
  223. }
  224. return true
  225. },
  226. handleUploadSuccess(res, file) {
  227. // 获取富文本组件实例
  228. let quill = this.Quill
  229. // 如果上传成功
  230. if (res.code == 200) {
  231. // 获取光标所在位置
  232. this.form.imgUrl = res.data.src
  233. this.$forceUpdate()
  234. } else {
  235. this.$message.error('图片插入失败')
  236. }
  237. },
  238. handleUploadError() {
  239. this.$message.error('图片插入失败')
  240. },
  241. /** 查询轮播图列表 */
  242. getList() {
  243. this.$nextTick(() => {
  244. this.$refs.pagination.handleSearch(true)
  245. })
  246. },
  247. checkClose(done) {
  248. this.$confirm('是否关闭表单,关闭后数据将丢失?')
  249. .then(function () {
  250. done()
  251. })
  252. .then(() => {})
  253. .catch(() => {})
  254. },
  255. // 取消按钮
  256. cancel() {
  257. this.open = false
  258. this.reset()
  259. },
  260. // 表单重置
  261. reset() {
  262. this.form = {
  263. id: null,
  264. bannerType: this.bannerType,
  265. imgUrl: null,
  266. clickType: null,
  267. redirectContent: null,
  268. status: '0'
  269. }
  270. this.resetForm('form')
  271. },
  272. /** 搜索按钮操作 */
  273. handleQuery() {
  274. this.getList()
  275. },
  276. /** 重置按钮操作 */
  277. resetQuery() {
  278. this.resetForm('queryForm')
  279. this.handleQuery()
  280. },
  281. // 多选框选中数据
  282. handleSelectionChange(selection) {
  283. this.ids = selection.map((item) => item.id)
  284. this.single = selection.length !== 1
  285. this.multiple = !selection.length
  286. },
  287. /** 新增按钮操作 */
  288. handleAdd() {
  289. this.reset()
  290. this.open = true
  291. this.title = '添加轮播图'
  292. },
  293. /** 修改按钮操作 */
  294. handleUpdate(row) {
  295. this.reset()
  296. const id = row.id || this.ids
  297. getBanner(id).then((response) => {
  298. this.form = response.data
  299. this.open = true
  300. this.title = '修改轮播图'
  301. })
  302. },
  303. /** 提交按钮 */
  304. submitForm() {
  305. this.$refs['form'].validate((valid) => {
  306. if (valid) {
  307. if (this.form.id != null) {
  308. updateBanner(this.form).then((response) => {
  309. this.$modal.msgSuccess('修改成功')
  310. this.open = false
  311. this.getList()
  312. })
  313. } else {
  314. addBanner(this.form).then((response) => {
  315. this.$modal.msgSuccess('新增成功')
  316. this.open = false
  317. this.getList()
  318. })
  319. }
  320. }
  321. })
  322. },
  323. /** 删除按钮操作 */
  324. handleDelete(row) {
  325. const ids = row.id || this.ids
  326. this.$modal
  327. .confirm('是否确认删除轮播图编号为"' + ids + '"的数据项?')
  328. .then(function () {
  329. return delBanner(ids)
  330. })
  331. .then(() => {
  332. this.getList()
  333. this.$modal.msgSuccess('删除成功')
  334. })
  335. .catch(() => {})
  336. },
  337. /** 导出按钮操作 */
  338. handleExport() {
  339. this.download(
  340. 'app/banner/export',
  341. {
  342. ...this.queryParams
  343. },
  344. `banner_${new Date().getTime()}.xlsx`
  345. )
  346. }
  347. }
  348. }
  349. </script>