index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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="advTitle">
  5. <el-input
  6. v-model="queryParams.advTitle"
  7. placeholder="请输入标题名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="状态" prop="status">
  14. <el-select v-model="queryParams.status" placeholder="状态" clearable size="small">
  15. <el-option
  16. v-for="dict in statusOptions"
  17. :key="dict.dictValue"
  18. :label="dict.dictLabel"
  19. :value="dict.dictValue"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="显示类型" prop="showType">
  24. <el-select v-model="queryParams.showType" placeholder="展示类型" clearable size="small">
  25. <el-option
  26. v-for="dict in showOptions"
  27. :key="dict.dictValue"
  28. :label="dict.dictLabel"
  29. :value="dict.dictValue"
  30. />
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item label="广告类型" prop="advType">
  34. <el-select v-model="queryParams.advType" placeholder="广告类型" clearable size="small">
  35. <el-option
  36. v-for="dict in devOptions"
  37. :key="dict.dictValue"
  38. :label="dict.dictLabel"
  39. :value="dict.dictValue"
  40. />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  45. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  46. </el-form-item>
  47. </el-form>
  48. <el-row :gutter="10" class="mb8">
  49. <el-col :span="1.5">
  50. <el-button
  51. type="primary"
  52. plain
  53. icon="el-icon-plus"
  54. size="mini"
  55. @click="handleAdd"
  56. v-hasPermi="['his:adv:add']"
  57. >新增</el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="success"
  62. plain
  63. icon="el-icon-edit"
  64. size="mini"
  65. :disabled="single"
  66. @click="handleUpdate"
  67. v-hasPermi="['his:adv:edit']"
  68. >修改</el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="danger"
  73. plain
  74. icon="el-icon-delete"
  75. size="mini"
  76. :disabled="multiple"
  77. @click="handleDelete"
  78. v-hasPermi="['his:adv:remove']"
  79. >删除</el-button>
  80. </el-col>
  81. <el-col :span="1.5">
  82. <el-button
  83. type="warning"
  84. plain
  85. icon="el-icon-download"
  86. size="mini"
  87. :loading="exportLoading"
  88. @click="handleExport"
  89. v-hasPermi="['his:adv:export']"
  90. >导出</el-button>
  91. </el-col>
  92. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  93. </el-row>
  94. <el-table v-loading="loading" :data="advList" @selection-change="handleSelectionChange" border>
  95. <el-table-column type="selection" width="55" align="center" />
  96. <el-table-column label="标题名称" align="center" prop="advTitle" width="150px"/>
  97. <el-table-column label="图片" align="center" prop="imageUrl" width="150px">
  98. <template slot-scope="scope">
  99. <el-popover
  100. placement="right"
  101. title=""
  102. trigger="hover">
  103. <img slot="reference" :src="scope.row.imageUrl" width="100">
  104. <img :src="scope.row.imageUrl" style="max-width: 150px;">
  105. </el-popover>
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="地址" show-overflow-tooltip align="center" prop="advUrl" width="150px" />
  109. <el-table-column label="排序" align="center" prop="sort" />
  110. <el-table-column label="类型" align="center" prop="advType" width="130px">
  111. <template slot-scope="scope">
  112. <dict-tag :options="devOptions" :value="scope.row.advType"/>
  113. </template>
  114. </el-table-column>
  115. <el-table-column label="显示类型" align="center" prop="showType" width="130px">
  116. <template slot-scope="scope">
  117. <dict-tag :options="showOptions" :value="scope.row.showType"/>
  118. </template>
  119. </el-table-column>
  120. <el-table-column label="状态" align="center" prop="status" >
  121. <template slot-scope="scope">
  122. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  123. </template>
  124. </el-table-column>
  125. <el-table-column label="创建时间" align="center" prop="createTime" width="150px" />
  126. <el-table-column label="修改时间" align="center" prop="updateTime" width="150px" />
  127. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150px">
  128. <template slot-scope="scope">
  129. <el-button
  130. size="mini"
  131. type="text"
  132. icon="el-icon-edit"
  133. @click="handleUpdate(scope.row)"
  134. v-hasPermi="['his:adv:edit']"
  135. >修改</el-button>
  136. <el-button
  137. size="mini"
  138. type="text"
  139. icon="el-icon-delete"
  140. @click="handleDelete(scope.row)"
  141. v-hasPermi="['his:adv:remove']"
  142. >删除</el-button>
  143. </template>
  144. </el-table-column>
  145. </el-table>
  146. <pagination
  147. v-show="total>0"
  148. :total="total"
  149. :page.sync="queryParams.pageNum"
  150. :limit.sync="queryParams.pageSize"
  151. @pagination="getList"
  152. />
  153. <!-- 添加或修改广告对话框 -->
  154. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  155. <el-form ref="form" :model="form" :rules="rules" label-width="90px">
  156. <el-form-item label="标题名称" prop="advTitle">
  157. <el-input v-model="form.advTitle" placeholder="请输入广告标题" />
  158. </el-form-item>
  159. <el-form-item label="图片" prop="imageUrl" >
  160. <el-upload
  161. v-model="form.imageUrl"
  162. class="avatar-uploader"
  163. :action="uploadUrl"
  164. :show-file-list="false"
  165. :on-success="handleAvatarSuccess"
  166. :before-upload="beforeAvatarUpload">
  167. <img v-if="form.imageUrl" :src="form.imageUrl" class="avatar" width="300px">
  168. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  169. </el-upload>
  170. </el-form-item>
  171. <el-form-item label="类型" prop="advType">
  172. <el-select v-model="form.advType" placeholder="请选择类型" >
  173. <el-option
  174. v-for="item in devOptions"
  175. :key="item.dictValue"
  176. :label="item.dictLabel"
  177. :value="item.dictValue"
  178. ></el-option>
  179. </el-select>
  180. </el-form-item>
  181. <el-form-item label="显示类型" prop="showType">
  182. <el-radio-group v-model="form.showType">
  183. <el-radio :label="item.dictValue" v-for="item in showOptions" >{{item.dictLabel}}</el-radio>
  184. </el-radio-group>
  185. </el-form-item>
  186. <el-form-item label="公众号链接" prop="advUrl" v-if="form.showType==1">
  187. <el-input v-model="form.advUrl" placeholder="请输入公众号链接" />
  188. </el-form-item>
  189. <el-form-item label="小程序地址" prop="advUrl" v-if="form.showType==2">
  190. <el-input v-model="form.advUrl" placeholder="请输入小程序地址" />
  191. </el-form-item>
  192. <el-form-item label="APP地址" prop="advUrl" v-if="form.showType==2||form.showType==4 ">
  193. <el-input v-model="form.appAdvUrl" placeholder="请输入APP地址" />
  194. </el-form-item>
  195. <el-form-item label="文章内容" v-show="form.showType==3">
  196. <editor ref="myeditor" @on-text-change="updateText" />
  197. </el-form-item>
  198. <el-form-item label="状态">
  199. <el-radio-group v-model="form.status">
  200. <el-radio :label="item.dictValue" v-for="item in statusOptions" >{{item.dictLabel}}</el-radio>
  201. </el-radio-group>
  202. </el-form-item>
  203. </el-form>
  204. <div slot="footer" class="dialog-footer">
  205. <el-button type="primary" @click="submitForm">确 定</el-button>
  206. <el-button @click="cancel">取 消</el-button>
  207. </div>
  208. </el-dialog>
  209. </div>
  210. </template>
  211. <script>
  212. import { listAdv, getAdv, delAdv, addAdv, updateAdv, exportAdv } from "@/api/his/adv";
  213. import Editor from '@/components/Editor/wang';
  214. export default {
  215. name: "Adv",
  216. components: { Editor },
  217. data() {
  218. return {
  219. uploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS",
  220. baseUrl: process.env.VUE_APP_BASE_API,
  221. showOptions: [],
  222. devOptions: [],
  223. statusOptions: [],
  224. // 遮罩层
  225. loading: true,
  226. // 导出遮罩层
  227. exportLoading: false,
  228. // 选中数组
  229. ids: [],
  230. // 非单个禁用
  231. single: true,
  232. // 非多个禁用
  233. multiple: true,
  234. // 显示搜索条件
  235. showSearch: true,
  236. // 总条数
  237. total: 0,
  238. // 广告表格数据
  239. advList: [],
  240. // 弹出层标题
  241. title: "",
  242. // 是否显示弹出层
  243. open: false,
  244. // 查询参数
  245. queryParams: {
  246. pageNum: 1,
  247. pageSize: 10,
  248. advTitle: null,
  249. imageUrl: null,
  250. advUrl: null,
  251. content: null,
  252. status: null,
  253. sort: null,
  254. advType: null,
  255. showType: null
  256. },
  257. // 表单参数
  258. form: {},
  259. // 表单校验
  260. rules: {
  261. advTitle: [
  262. { required: true, message: "标题不能为空", trigger: "blur" }
  263. ],
  264. status: [
  265. { required: true, message: "状态不能为空", trigger: "blur" }
  266. ],
  267. sort: [
  268. { required: true, message: "排序不能为空", trigger: "blur" }
  269. ],
  270. advType: [
  271. { required: true, message: "类别不能为空", trigger: "blur" }
  272. ],
  273. showType: [
  274. { required: true, message: "显示类别不能为空", trigger: "blur" }
  275. ],
  276. }
  277. };
  278. },
  279. created() {
  280. this.getList();
  281. this.getDicts("sys_company_status").then(response => {
  282. this.statusOptions = response.data;
  283. });
  284. this.getDicts("sys_adv_show").then(response => {
  285. this.showOptions = response.data;
  286. });
  287. this.getDicts("sys_adv_type").then(response => {
  288. this.devOptions = response.data;
  289. });
  290. },
  291. methods: {
  292. updateText(text){
  293. this.form.content=text
  294. },
  295. handleAvatarSuccess(res, file) {
  296. if(res.code==200){
  297. this.form.imageUrl=res.url;
  298. self.$forceUpdate()
  299. }
  300. else{
  301. this.msgError(res.msg);
  302. }
  303. },
  304. beforeAvatarUpload(file) {
  305. const isLt1M = file.size / 1024 / 1024 < 1;
  306. if (!isLt1M) {
  307. this.$message.error('上传图片大小不能超过 1MB!');
  308. }
  309. return isLt1M;
  310. },
  311. /** 查询广告列表 */
  312. getList() {
  313. this.loading = true;
  314. listAdv(this.queryParams).then(response => {
  315. this.advList = response.rows;
  316. this.total = response.total;
  317. this.loading = false;
  318. });
  319. },
  320. // 取消按钮
  321. cancel() {
  322. this.open = false;
  323. this.reset();
  324. },
  325. // 表单重置
  326. reset() {
  327. this.form = {
  328. advId: null,
  329. advTitle: null,
  330. imageUrl: null,
  331. advUrl: null,
  332. appAdvUrl: null,
  333. content: null,
  334. createTime: null,
  335. updateTime: null,
  336. status: "0",
  337. sort: null,
  338. advType: null,
  339. showType: null
  340. };
  341. this.resetForm("form");
  342. },
  343. /** 搜索按钮操作 */
  344. handleQuery() {
  345. this.queryParams.pageNum = 1;
  346. this.getList();
  347. },
  348. /** 重置按钮操作 */
  349. resetQuery() {
  350. this.resetForm("queryForm");
  351. this.handleQuery();
  352. },
  353. // 多选框选中数据
  354. handleSelectionChange(selection) {
  355. this.ids = selection.map(item => item.advId)
  356. this.single = selection.length!==1
  357. this.multiple = !selection.length
  358. },
  359. /** 新增按钮操作 */
  360. handleAdd() {
  361. this.reset();
  362. this.open = true;
  363. this.title = "添加广告";
  364. setTimeout(() => {
  365. this.$refs.myeditor.setText("");
  366. }, 100);
  367. },
  368. /** 修改按钮操作 */
  369. handleUpdate(row) {
  370. this.reset();
  371. const advId = row.advId || this.ids
  372. getAdv(advId).then(response => {
  373. this.form = response.data;
  374. this.open = true;
  375. this.title = "修改广告";
  376. this.form.advType = String(this.form.advType)
  377. this.form.showType = String(this.form.showType)
  378. setTimeout(() => {
  379. if(this.form.content==null){
  380. this.$refs.myeditor.setText("");
  381. }
  382. else{
  383. this.$refs.myeditor.setText(this.form.content);
  384. }
  385. }, 1);
  386. });
  387. },
  388. /** 提交按钮 */
  389. submitForm() {
  390. this.$refs["form"].validate(valid => {
  391. if (valid) {
  392. if (this.form.advId != null) {
  393. updateAdv(this.form).then(response => {
  394. this.msgSuccess("修改成功");
  395. this.open = false;
  396. this.getList();
  397. });
  398. } else {
  399. addAdv(this.form).then(response => {
  400. this.msgSuccess("新增成功");
  401. this.open = false;
  402. this.getList();
  403. });
  404. }
  405. }
  406. });
  407. },
  408. /** 删除按钮操作 */
  409. handleDelete(row) {
  410. const advIds = row.advId || this.ids;
  411. this.$confirm('是否确认删除广告编号为"' + advIds + '"的数据项?', "警告", {
  412. confirmButtonText: "确定",
  413. cancelButtonText: "取消",
  414. type: "warning"
  415. }).then(function() {
  416. return delAdv(advIds);
  417. }).then(() => {
  418. this.getList();
  419. this.msgSuccess("删除成功");
  420. }).catch(() => {});
  421. },
  422. /** 导出按钮操作 */
  423. handleExport() {
  424. const queryParams = this.queryParams;
  425. this.$confirm('是否确认导出所有广告数据项?', "警告", {
  426. confirmButtonText: "确定",
  427. cancelButtonText: "取消",
  428. type: "warning"
  429. }).then(() => {
  430. this.exportLoading = true;
  431. return exportAdv(queryParams);
  432. }).then(response => {
  433. this.download(response.msg);
  434. this.exportLoading = false;
  435. }).catch(() => {});
  436. }
  437. }
  438. };
  439. </script>
  440. <style>
  441. .avatar-uploader .el-upload {
  442. border: 1px dashed #d9d9d9;
  443. border-radius: 6px;
  444. cursor: pointer;
  445. position: relative;
  446. overflow: hidden;
  447. }
  448. .avatar-uploader .el-upload:hover {
  449. border-color: #409EFF;
  450. }
  451. .avatar-uploader-icon {
  452. font-size: 28px;
  453. color: #8c939d;
  454. width: 150px;
  455. height: 150px;
  456. line-height: 150px;
  457. text-align: center;
  458. }
  459. </style>