index.vue 10 KB

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