index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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="title">
  5. <el-input v-model="queryParams.title" placeholder="请输入公告标题" clearable size="small" @keyup.enter.native="handleQuery"/>
  6. </el-form-item>
  7. <el-form-item label="操作人员" prop="createBy">
  8. <el-input v-model="queryParams.createBy" placeholder="请输入操作人员" clearable size="small" @keyup.enter.native="handleQuery"/>
  9. </el-form-item>
  10. <el-form-item label="类型" prop="type">
  11. <el-select v-model="queryParams.type" placeholder="公告类型" clearable size="small">
  12. <el-option v-for="dict in noticeTypeDictDatas" :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  17. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  18. </el-form-item>
  19. </el-form>
  20. <el-row :gutter="10" class="mb8">
  21. <el-col :span="1.5">
  22. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  23. v-hasPermi="['system:notice:create']"s>新增</el-button>
  24. </el-col>
  25. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  26. </el-row>
  27. <el-table v-loading="loading" :data="noticeList">
  28. <el-table-column label="序号" align="center" prop="id" width="100" />
  29. <el-table-column label="公告标题" align="center" prop="title" :show-overflow-tooltip="true"/>
  30. <el-table-column label="公告类型" align="center" prop="type" :formatter="typeFormat" width="100"/>
  31. <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" width="100"/>
  32. <el-table-column label="创建者" align="center" prop="createBy" width="100" />
  33. <el-table-column label="创建时间" align="center" prop="createTime" width="100">
  34. <template slot-scope="scope">
  35. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  39. <template slot-scope="scope">
  40. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  41. v-hasPermi="['system:notice:update']">修改</el-button>
  42. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  43. v-hasPermi="['system:notice:delete']">删除</el-button>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  48. @pagination="getList"/>
  49. <!-- 添加或修改公告对话框 -->
  50. <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
  51. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  52. <el-row>
  53. <el-col :span="12">
  54. <el-form-item label="公告标题" prop="title">
  55. <el-input v-model="form.title" placeholder="请输入公告标题" />
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="12">
  59. <el-form-item label="公告类型" prop="type">
  60. <el-select v-model="form.type" placeholder="请选择">
  61. <el-option
  62. v-for="dict in noticeTypeDictDatas"
  63. :key="parseInt(dict.value)"
  64. :label="dict.label"
  65. :value="parseInt(dict.value)"
  66. />
  67. </el-select>
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="24">
  71. <el-form-item label="状态">
  72. <el-radio-group v-model="form.status">
  73. <el-radio
  74. v-for="dict in statusDictDatas"
  75. :key="parseInt(dict.value)"
  76. :label="parseInt(dict.value)"
  77. >{{dict.label}}</el-radio>
  78. </el-radio-group>
  79. </el-form-item>
  80. </el-col>
  81. <el-col :span="24">
  82. <el-form-item label="内容">
  83. <editor v-model="form.content" :min-height="192"/>
  84. </el-form-item>
  85. </el-col>
  86. </el-row>
  87. </el-form>
  88. <div slot="footer" class="dialog-footer">
  89. <el-button type="primary" @click="submitForm">确 定</el-button>
  90. <el-button @click="cancel">取 消</el-button>
  91. </div>
  92. </el-dialog>
  93. </div>
  94. </template>
  95. <script>
  96. import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/system/notice";
  97. import Editor from '@/components/Editor';
  98. import {CommonStatusEnum} from '@/utils/constants'
  99. import { getDictDataLabel, getDictDatas, DICT_TYPE } from '@/utils/dict'
  100. export default {
  101. name: "Notice",
  102. components: {
  103. Editor
  104. },
  105. data() {
  106. return {
  107. // 遮罩层
  108. loading: true,
  109. // 显示搜索条件
  110. showSearch: true,
  111. // 总条数
  112. total: 0,
  113. // 公告表格数据
  114. noticeList: [],
  115. // 弹出层标题
  116. title: "",
  117. // 是否显示弹出层
  118. open: false,
  119. // 查询参数
  120. queryParams: {
  121. pageNo: 1,
  122. pageSize: 10,
  123. title: undefined,
  124. createBy: undefined,
  125. status: undefined
  126. },
  127. // 表单参数
  128. form: {},
  129. // 表单校验
  130. rules: {
  131. title: [
  132. { required: true, message: "公告标题不能为空", trigger: "blur" }
  133. ],
  134. type: [
  135. { required: true, message: "公告类型不能为空", trigger: "change" }
  136. ]
  137. },
  138. // 枚举
  139. CommonStatusEnum: CommonStatusEnum,
  140. // 数据字典
  141. noticeTypeDictDatas: getDictDatas(DICT_TYPE.SYSTEM_NOTICE_TYPE),
  142. statusDictDatas: getDictDatas(DICT_TYPE.COMMON_STATUS)
  143. };
  144. },
  145. created() {
  146. this.getList();
  147. },
  148. methods: {
  149. /** 查询公告列表 */
  150. getList() {
  151. this.loading = true;
  152. listNotice(this.queryParams).then(response => {
  153. this.noticeList = response.data.list;
  154. this.total = response.data.total;
  155. this.loading = false;
  156. });
  157. },
  158. // 公告状态字典翻译
  159. statusFormat(row, column) {
  160. return getDictDataLabel(DICT_TYPE.COMMON_STATUS, row.status)
  161. },
  162. // 公告状态字典翻译
  163. typeFormat(row, column) {
  164. return getDictDataLabel(DICT_TYPE.SYSTEM_NOTICE_TYPE, row.type)
  165. },
  166. // 取消按钮
  167. cancel() {
  168. this.open = false;
  169. this.reset();
  170. },
  171. // 表单重置
  172. reset() {
  173. this.form = {
  174. id: undefined,
  175. title: undefined,
  176. type: undefined,
  177. content: undefined,
  178. status: CommonStatusEnum.ENABLE
  179. };
  180. this.resetForm("form");
  181. },
  182. /** 搜索按钮操作 */
  183. handleQuery() {
  184. this.queryParams.pageNo = 1;
  185. this.getList();
  186. },
  187. /** 重置按钮操作 */
  188. resetQuery() {
  189. this.resetForm("queryForm");
  190. this.handleQuery();
  191. },
  192. /** 新增按钮操作 */
  193. handleAdd() {
  194. this.reset();
  195. this.open = true;
  196. this.title = "添加公告";
  197. },
  198. /** 修改按钮操作 */
  199. handleUpdate(row) {
  200. this.reset();
  201. const id = row.id || this.ids
  202. getNotice(id).then(response => {
  203. this.form = response.data;
  204. this.open = true;
  205. this.title = "修改公告";
  206. });
  207. },
  208. /** 提交按钮 */
  209. submitForm: function() {
  210. this.$refs["form"].validate(valid => {
  211. if (valid) {
  212. if (this.form.id !== undefined) {
  213. updateNotice(this.form).then(response => {
  214. this.msgSuccess("修改成功");
  215. this.open = false;
  216. this.getList();
  217. });
  218. } else {
  219. addNotice(this.form).then(response => {
  220. this.msgSuccess("新增成功");
  221. this.open = false;
  222. this.getList();
  223. });
  224. }
  225. }
  226. });
  227. },
  228. /** 删除按钮操作 */
  229. handleDelete(row) {
  230. const ids = row.id || this.ids
  231. this.$confirm('是否确认删除公告编号为"' + ids + '"的数据项?', "警告", {
  232. confirmButtonText: "确定",
  233. cancelButtonText: "取消",
  234. type: "warning"
  235. }).then(function() {
  236. return delNotice(ids);
  237. }).then(() => {
  238. this.getList();
  239. this.msgSuccess("删除成功");
  240. }).catch(() => {});
  241. }
  242. }
  243. };
  244. </script>