index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
  4. <el-form-item label="公告标题" prop="noticeTitle">
  5. <el-input
  6. v-model="queryParams.noticeTitle"
  7. placeholder="请输入公告标题"
  8. clearable
  9. style="width: 200px"
  10. @keyup.enter="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. style="width: 200px"
  19. @keyup.enter="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="类型" prop="noticeType">
  23. <el-select v-model="queryParams.noticeType" placeholder="公告类型" clearable style="width: 200px">
  24. <el-option
  25. v-for="dict in sys_notice_type"
  26. :key="dict.value"
  27. :label="dict.label"
  28. :value="dict.value"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  34. <el-button icon="Refresh" @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. plain
  42. icon="Plus"
  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. plain
  51. icon="Edit"
  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. plain
  61. icon="Delete"
  62. :disabled="multiple"
  63. @click="handleDelete"
  64. v-hasPermi="['system:notice:remove']"
  65. >删除</el-button>
  66. </el-col>
  67. <right-toolbar v-model:showSearch="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 label="公告类型" align="center" prop="noticeType" width="100">
  79. <template #default="scope">
  80. <dict-tag :options="sys_notice_type" :value="scope.row.noticeType" />
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="状态" align="center" prop="status" width="100">
  84. <template #default="scope">
  85. <dict-tag :options="sys_notice_status" :value="scope.row.status" />
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="创建者" align="center" prop="createBy" width="100" />
  89. <el-table-column label="创建时间" align="center" prop="createTime" width="100">
  90. <template #default="scope">
  91. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  92. </template>
  93. </el-table-column>
  94. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  95. <template #default="scope">
  96. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:notice:edit']">修改</el-button>
  97. <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:notice:remove']" >删除</el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. <pagination
  102. v-show="total > 0"
  103. :total="total"
  104. v-model:page="queryParams.pageNum"
  105. v-model:limit="queryParams.pageSize"
  106. @pagination="getList"
  107. />
  108. <!-- 添加或修改公告对话框 -->
  109. <el-dialog :title="title" v-model="open" width="780px" append-to-body>
  110. <el-form ref="noticeRef" :model="form" :rules="rules" label-width="80px">
  111. <el-row>
  112. <el-col :span="12">
  113. <el-form-item label="公告标题" prop="noticeTitle">
  114. <el-input v-model="form.noticeTitle" placeholder="请输入公告标题" />
  115. </el-form-item>
  116. </el-col>
  117. <el-col :span="12">
  118. <el-form-item label="公告类型" prop="noticeType">
  119. <el-select v-model="form.noticeType" placeholder="请选择">
  120. <el-option
  121. v-for="dict in sys_notice_type"
  122. :key="dict.value"
  123. :label="dict.label"
  124. :value="dict.value"
  125. ></el-option>
  126. </el-select>
  127. </el-form-item>
  128. </el-col>
  129. <el-col :span="24">
  130. <el-form-item label="状态">
  131. <el-radio-group v-model="form.status">
  132. <el-radio
  133. v-for="dict in sys_notice_status"
  134. :key="dict.value"
  135. :label="dict.value"
  136. >{{ dict.label }}</el-radio>
  137. </el-radio-group>
  138. </el-form-item>
  139. </el-col>
  140. <el-col :span="24">
  141. <el-form-item label="内容">
  142. <el-input
  143. :rows="6"
  144. type="textarea"
  145. placeholder="请输入内容"
  146. v-model="form.noticeContent"
  147. />
  148. </el-form-item>
  149. </el-col>
  150. </el-row>
  151. </el-form>
  152. <template #footer>
  153. <div class="dialog-footer">
  154. <el-button type="primary" @click="submitForm">确 定</el-button>
  155. <el-button @click="cancel">取 消</el-button>
  156. </div>
  157. </template>
  158. </el-dialog>
  159. </div>
  160. </template>
  161. <script setup name="Notice">
  162. import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/system/notice";
  163. const { proxy } = getCurrentInstance();
  164. const { sys_notice_status, sys_notice_type } = proxy.useDict("sys_notice_status", "sys_notice_type");
  165. const noticeList = ref([]);
  166. const open = ref(false);
  167. const loading = ref(true);
  168. const showSearch = ref(true);
  169. const ids = ref([]);
  170. const single = ref(true);
  171. const multiple = ref(true);
  172. const total = ref(0);
  173. const title = ref("");
  174. const data = reactive({
  175. form: {},
  176. queryParams: {
  177. pageNum: 1,
  178. pageSize: 10,
  179. noticeTitle: undefined,
  180. createBy: undefined,
  181. status: undefined
  182. },
  183. rules: {
  184. noticeTitle: [{ required: true, message: "公告标题不能为空", trigger: "blur" }],
  185. noticeType: [{ required: true, message: "公告类型不能为空", trigger: "change" }]
  186. },
  187. });
  188. const { queryParams, form, rules } = toRefs(data);
  189. /** 查询公告列表 */
  190. function getList() {
  191. loading.value = true;
  192. listNotice(queryParams.value).then(response => {
  193. noticeList.value = response.rows;
  194. total.value = response.total;
  195. loading.value = false;
  196. });
  197. }
  198. /** 取消按钮 */
  199. function cancel() {
  200. open.value = false;
  201. reset();
  202. }
  203. /** 表单重置 */
  204. function reset() {
  205. form.value = {
  206. noticeId: undefined,
  207. noticeTitle: undefined,
  208. noticeType: undefined,
  209. noticeContent: undefined,
  210. status: "0"
  211. };
  212. proxy.resetForm("noticeRef");
  213. }
  214. /** 搜索按钮操作 */
  215. function handleQuery() {
  216. queryParams.value.pageNum = 1;
  217. getList();
  218. }
  219. /** 重置按钮操作 */
  220. function resetQuery() {
  221. proxy.resetForm("queryRef");
  222. handleQuery();
  223. }
  224. /** 多选框选中数据 */
  225. function handleSelectionChange(selection) {
  226. ids.value = selection.map(item => item.noticeId);
  227. single.value = selection.length != 1;
  228. multiple.value = !selection.length;
  229. }
  230. /** 新增按钮操作 */
  231. function handleAdd() {
  232. reset();
  233. open.value = true;
  234. title.value = "添加公告";
  235. }
  236. /**修改按钮操作 */
  237. function handleUpdate(row) {
  238. reset();
  239. const noticeId = row.noticeId || ids.value;
  240. getNotice(noticeId).then(response => {
  241. form.value = response.data;
  242. open.value = true;
  243. title.value = "修改公告";
  244. });
  245. }
  246. /** 提交按钮 */
  247. function submitForm() {
  248. proxy.$refs["noticeRef"].validate(valid => {
  249. if (valid) {
  250. if (form.value.noticeId != undefined) {
  251. updateNotice(form.value).then(response => {
  252. proxy.$modal.msgSuccess("修改成功");
  253. open.value = false;
  254. getList();
  255. });
  256. } else {
  257. addNotice(form.value).then(response => {
  258. proxy.$modal.msgSuccess("新增成功");
  259. open.value = false;
  260. getList();
  261. });
  262. }
  263. }
  264. });
  265. }
  266. /** 删除按钮操作 */
  267. function handleDelete(row) {
  268. const noticeIds = row.noticeId || ids.value
  269. proxy.$modal.confirm('是否确认删除公告编号为"' + noticeIds + '"的数据项?').then(function() {
  270. return delNotice(noticeIds);
  271. }).then(() => {
  272. getList();
  273. proxy.$modal.msgSuccess("删除成功");
  274. }).catch(() => {});
  275. }
  276. getList();
  277. </script>