index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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="noticeTitle">
  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="操作人员" prop="createBy">
  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="类型" prop="noticeType">
  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="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  34. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  35. </el-form-item>
  36. </el-form>
  37. <el-row :gutter="10" class="mb8">
  38. <el-col :span="1.5">
  39. <el-button
  40. type="primary"
  41. icon="el-icon-plus"
  42. size="mini"
  43. @click="handleAdd"
  44. v-hasPermi="['system:notice:add']"
  45. >新增</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button
  49. type="success"
  50. icon="el-icon-edit"
  51. size="mini"
  52. :disabled="single"
  53. @click="handleUpdate"
  54. v-hasPermi="['system:notice:edit']"
  55. >修改</el-button>
  56. </el-col>
  57. <el-col :span="1.5">
  58. <el-button
  59. type="danger"
  60. icon="el-icon-delete"
  61. size="mini"
  62. :disabled="multiple"
  63. @click="handleDelete"
  64. v-hasPermi="['system:notice:remove']"
  65. >删除</el-button>
  66. </el-col>
  67. <div class="top-right-btn">
  68. <el-tooltip class="item" effect="dark" content="刷新" placement="top">
  69. <el-button size="mini" circle icon="el-icon-refresh" @click="handleQuery" />
  70. </el-tooltip>
  71. <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
  72. <el-button size="mini" circle icon="el-icon-search" @click="showSearch=!showSearch" />
  73. </el-tooltip>
  74. </div>
  75. </el-row>
  76. <el-table v-loading="loading" :data="noticeList" @selection-change="handleSelectionChange">
  77. <el-table-column type="selection" width="55" align="center" />
  78. <el-table-column label="序号" align="center" prop="noticeId" width="100" />
  79. <el-table-column
  80. label="公告标题"
  81. align="center"
  82. prop="noticeTitle"
  83. :show-overflow-tooltip="true"
  84. />
  85. <el-table-column
  86. label="公告类型"
  87. align="center"
  88. prop="noticeType"
  89. :formatter="typeFormat"
  90. width="100"
  91. />
  92. <el-table-column
  93. label="状态"
  94. align="center"
  95. prop="status"
  96. :formatter="statusFormat"
  97. width="100"
  98. />
  99. <el-table-column label="创建者" align="center" prop="createBy" width="100" />
  100. <el-table-column label="创建时间" align="center" prop="createTime" width="100">
  101. <template slot-scope="scope">
  102. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  106. <template slot-scope="scope">
  107. <el-button
  108. size="mini"
  109. type="text"
  110. icon="el-icon-edit"
  111. @click="handleUpdate(scope.row)"
  112. v-hasPermi="['system:notice:edit']"
  113. >修改</el-button>
  114. <el-button
  115. size="mini"
  116. type="text"
  117. icon="el-icon-delete"
  118. @click="handleDelete(scope.row)"
  119. v-hasPermi="['system:notice:remove']"
  120. >删除</el-button>
  121. </template>
  122. </el-table-column>
  123. </el-table>
  124. <pagination
  125. v-show="total>0"
  126. :total="total"
  127. :page.sync="queryParams.pageNum"
  128. :limit.sync="queryParams.pageSize"
  129. @pagination="getList"
  130. />
  131. <!-- 添加或修改公告对话框 -->
  132. <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
  133. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  134. <el-row>
  135. <el-col :span="12">
  136. <el-form-item label="公告标题" prop="noticeTitle">
  137. <el-input v-model="form.noticeTitle" placeholder="请输入公告标题" />
  138. </el-form-item>
  139. </el-col>
  140. <el-col :span="12">
  141. <el-form-item label="公告类型" prop="noticeType">
  142. <el-select v-model="form.noticeType" placeholder="请选择">
  143. <el-option
  144. v-for="dict in typeOptions"
  145. :key="dict.dictValue"
  146. :label="dict.dictLabel"
  147. :value="dict.dictValue"
  148. ></el-option>
  149. </el-select>
  150. </el-form-item>
  151. </el-col>
  152. <el-col :span="24">
  153. <el-form-item label="状态">
  154. <el-radio-group v-model="form.status">
  155. <el-radio
  156. v-for="dict in statusOptions"
  157. :key="dict.dictValue"
  158. :label="dict.dictValue"
  159. >{{dict.dictLabel}}</el-radio>
  160. </el-radio-group>
  161. </el-form-item>
  162. </el-col>
  163. <el-col :span="24">
  164. <el-form-item label="内容">
  165. <Editor v-model="form.noticeContent" />
  166. </el-form-item>
  167. </el-col>
  168. </el-row>
  169. </el-form>
  170. <div slot="footer" class="dialog-footer" style="padding-top:20px">
  171. <el-button type="primary" @click="submitForm">确 定</el-button>
  172. <el-button @click="cancel">取 消</el-button>
  173. </div>
  174. </el-dialog>
  175. </div>
  176. </template>
  177. <script>
  178. import { listNotice, getNotice, delNotice, addNotice, updateNotice, exportNotice } from "@/api/system/notice";
  179. import Editor from '@/components/Editor';
  180. export default {
  181. name: "Notice",
  182. components: {
  183. Editor
  184. },
  185. data() {
  186. return {
  187. // 遮罩层
  188. loading: true,
  189. // 选中数组
  190. ids: [],
  191. // 非单个禁用
  192. single: true,
  193. // 非多个禁用
  194. multiple: true,
  195. // 显示搜索条件
  196. showSearch: true,
  197. // 总条数
  198. total: 0,
  199. // 公告表格数据
  200. noticeList: [],
  201. // 弹出层标题
  202. title: "",
  203. // 是否显示弹出层
  204. open: false,
  205. // 类型数据字典
  206. statusOptions: [],
  207. // 状态数据字典
  208. typeOptions: [],
  209. // 查询参数
  210. queryParams: {
  211. pageNum: 1,
  212. pageSize: 10,
  213. noticeTitle: undefined,
  214. createBy: undefined,
  215. status: undefined
  216. },
  217. // 表单参数
  218. form: {},
  219. // 表单校验
  220. rules: {
  221. noticeTitle: [
  222. { required: true, message: "公告标题不能为空", trigger: "blur" }
  223. ],
  224. noticeType: [
  225. { required: true, message: "公告类型不能为空", trigger: "blur" }
  226. ]
  227. }
  228. };
  229. },
  230. created() {
  231. this.getList();
  232. this.getDicts("sys_notice_status").then(response => {
  233. this.statusOptions = response.data;
  234. });
  235. this.getDicts("sys_notice_type").then(response => {
  236. this.typeOptions = response.data;
  237. });
  238. },
  239. methods: {
  240. /** 查询公告列表 */
  241. getList() {
  242. this.loading = true;
  243. listNotice(this.queryParams).then(response => {
  244. this.noticeList = response.rows;
  245. this.total = response.total;
  246. this.loading = false;
  247. });
  248. },
  249. // 公告状态字典翻译
  250. statusFormat(row, column) {
  251. return this.selectDictLabel(this.statusOptions, row.status);
  252. },
  253. // 公告状态字典翻译
  254. typeFormat(row, column) {
  255. return this.selectDictLabel(this.typeOptions, row.noticeType);
  256. },
  257. // 取消按钮
  258. cancel() {
  259. this.open = false;
  260. this.reset();
  261. },
  262. // 表单重置
  263. reset() {
  264. this.form = {
  265. noticeId: undefined,
  266. noticeTitle: undefined,
  267. noticeType: undefined,
  268. noticeContent: undefined,
  269. status: "0"
  270. };
  271. this.resetForm("form");
  272. },
  273. /** 搜索按钮操作 */
  274. handleQuery() {
  275. this.queryParams.pageNum = 1;
  276. this.getList();
  277. },
  278. /** 重置按钮操作 */
  279. resetQuery() {
  280. this.resetForm("queryForm");
  281. this.handleQuery();
  282. },
  283. // 多选框选中数据
  284. handleSelectionChange(selection) {
  285. this.ids = selection.map(item => item.noticeId)
  286. this.single = selection.length!=1
  287. this.multiple = !selection.length
  288. },
  289. /** 新增按钮操作 */
  290. handleAdd() {
  291. this.reset();
  292. this.open = true;
  293. this.title = "添加公告";
  294. },
  295. /** 修改按钮操作 */
  296. handleUpdate(row) {
  297. this.reset();
  298. const noticeId = row.noticeId || this.ids
  299. getNotice(noticeId).then(response => {
  300. this.form = response.data;
  301. this.open = true;
  302. this.title = "修改公告";
  303. });
  304. },
  305. /** 提交按钮 */
  306. submitForm: function() {
  307. this.$refs["form"].validate(valid => {
  308. if (valid) {
  309. if (this.form.noticeId != undefined) {
  310. updateNotice(this.form).then(response => {
  311. if (response.code === 200) {
  312. this.msgSuccess("修改成功");
  313. this.open = false;
  314. this.getList();
  315. }
  316. });
  317. } else {
  318. addNotice(this.form).then(response => {
  319. if (response.code === 200) {
  320. this.msgSuccess("新增成功");
  321. this.open = false;
  322. this.getList();
  323. }
  324. });
  325. }
  326. }
  327. });
  328. },
  329. /** 删除按钮操作 */
  330. handleDelete(row) {
  331. const noticeIds = row.noticeId || this.ids
  332. this.$confirm('是否确认删除公告编号为"' + noticeIds + '"的数据项?', "警告", {
  333. confirmButtonText: "确定",
  334. cancelButtonText: "取消",
  335. type: "warning"
  336. }).then(function() {
  337. return delNotice(noticeIds);
  338. }).then(() => {
  339. this.getList();
  340. this.msgSuccess("删除成功");
  341. }).catch(function() {});
  342. }
  343. }
  344. };
  345. </script>