index.vue 8.9 KB

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