index.vue 10 KB

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