NewsClassification.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. <template>
  2. <div class="scroll">
  3. <div class="middle">
  4. <div class="filter">
  5. <div class="condition">
  6. <span>分类名称 :</span>
  7. <el-select
  8. clearable
  9. v-model="searchInput.year"
  10. placeholder="请选择分类名称"
  11. >
  12. <el-option
  13. v-for="i in yearData"
  14. :key="i.id"
  15. :label="i.name"
  16. :value="i.id"
  17. />
  18. </el-select>
  19. </div>
  20. <div class="condition">
  21. <span>创建人 :</span>
  22. <el-input
  23. clearable
  24. v-model.trim="searchInput.name"
  25. class="w-50 m-2"
  26. placeholder="请输入创建人"
  27. style="width: 180px"
  28. />
  29. </div>
  30. <div class="condition">
  31. <span>创建时间 :</span>
  32. <el-date-picker
  33. v-model="searchInput.createTime"
  34. unlink-panels
  35. type="datetimerange"
  36. range-separator="-"
  37. start-placeholder="起始时间"
  38. end-placeholder="结束时间"
  39. format="YYYY-MM-DD HH:mm:ss"
  40. value-format="YYYY-MM-DD HH:mm:ss"
  41. placeholder="请选择日期"
  42. />
  43. </div>
  44. <el-button
  45. style="margin-left: 20px"
  46. color="rgba(38, 151, 255, 1)"
  47. type="primary"
  48. class="search"
  49. @click="searchBtn"
  50. ><span>查询</span></el-button
  51. >
  52. <el-button @click="resetBtn" plain color="rgba(43, 153, 255, 1)"
  53. >重置</el-button
  54. >
  55. </div>
  56. <!-- 按钮列表 -->
  57. <div class="gongneng">
  58. <el-button
  59. type="primary"
  60. style="margin-left: 0"
  61. color="rgba(38, 151, 255, 1)"
  62. @click="addlist"
  63. >创建分类</el-button
  64. >
  65. </div>
  66. </div>
  67. <div class="footer" v-loading="loading">
  68. <div class="card_all">
  69. <el-space wrap>
  70. <el-card
  71. style="max-width: 480px"
  72. v-for="i in tableData.list"
  73. :key="i.id"
  74. >
  75. <template #header>
  76. <div class="card-header">
  77. <span>{{ i.name }}</span>
  78. <span><span class="number">1 </span>篇新闻</span>
  79. </div>
  80. </template>
  81. <p>创建时间: {{ i.createTime }}</p>
  82. <p>创建人: {{ i.createUser }}</p>
  83. <template #footer>
  84. <div class="card-footer">
  85. <el-button type="primary" @click="updateS(i)" link>编辑</el-button>
  86. <span class="line">|</span>
  87. <el-button type="danger" @click="deleteS(i)" link>删除</el-button>
  88. </div>
  89. </template>
  90. </el-card>
  91. </el-space>
  92. </div>
  93. <!-- 分页组件 -->
  94. <div class="pageSize">
  95. <span></span>
  96. <el-pagination
  97. background
  98. :current-page="currentPage"
  99. :page-size="pageSize"
  100. :page-sizes="[10, 20, 30, 40]"
  101. layout="total,sizes, prev, pager, next, jumper, slot"
  102. :total="total"
  103. @size-change="handleSizeChange"
  104. @update:current-page="handleCurrentChange"
  105. />
  106. </div>
  107. </div>
  108. </div>
  109. <!-- 添加账号弹窗 -->
  110. <el-dialog
  111. class="addStaff"
  112. v-model="addDialogVisible"
  113. :close-on-click-modal="false"
  114. :close-on-press-escape="false"
  115. :title="dialongTitle"
  116. align-center
  117. width="450"
  118. :before-close="cancelAdd"
  119. destroy-on-close
  120. draggable
  121. >
  122. <el-form
  123. ref="ruleFormRef"
  124. :model="ruleForm"
  125. :rules="rules"
  126. label-width="100px"
  127. class="demo-ruleForm"
  128. :size="formSize"
  129. label-position="right"
  130. status-icon
  131. >
  132. <el-form-item label="分类名称 :" prop="name">
  133. <el-input
  134. clearable
  135. v-model.trim="ruleForm.name"
  136. class="w-50 m-2"
  137. placeholder="请输入分类名称"
  138. />
  139. </el-form-item>
  140. <el-form-item class="options">
  141. <el-button @click="cancelAdd">取消</el-button>
  142. <el-button
  143. color="rgba(0, 97, 255, 1)"
  144. class="queding"
  145. type="primary"
  146. @click="submitAdd(ruleFormRef)"
  147. >
  148. 确定
  149. </el-button>
  150. </el-form-item>
  151. </el-form>
  152. </el-dialog>
  153. </template>
  154. <script setup>
  155. import {
  156. ref,
  157. watch,
  158. reactive,
  159. nextTick,
  160. onBeforeMount,
  161. onUnmounted,
  162. } from "vue";
  163. import { useRouter } from "vue-router";
  164. import { genFileId, ElMessage, ElMessageBox } from "element-plus";
  165. import { dayjs } from "element-plus";
  166. import lodash from "lodash";
  167. import { storeToRefs } from "pinia";
  168. import { useCounterStore } from "@/stores/index";
  169. import {
  170. queryCategoryNewsPage,
  171. insertCategoryNews,
  172. updateCategoryNews,
  173. deleteCategoryNews,
  174. queryCategoryNewss,
  175. queryAlumniNewsPage,
  176. insertAlumniNews,
  177. updateAlumniNews,
  178. deleteAlumniNews,
  179. } from "@/api/alumni-new.js";
  180. const router = useRouter();
  181. const store = useCounterStore();
  182. // 为避免解构时失去响应性
  183. const { name, age, isCollapse, realAge, collegeRole } = storeToRefs(store);
  184. // 表格数据
  185. const loading = ref(false);
  186. const tableData = reactive({
  187. list: [{}],
  188. });
  189. const activeIndex = ref(); // 默认跳转路由
  190. const dialongTitle = ref("新增账号"); // 弹窗标题
  191. const searchInput = reactive({
  192. name: "",
  193. year: null,
  194. college: null,
  195. major: null,
  196. class: null,
  197. }); // 搜索按钮数据
  198. const currentPage = ref(1); // 当前页
  199. const pageSize = ref(10);
  200. const total = ref(0); // 当前总数
  201. const selectIds = ref([]); // 勾选的全部数据
  202. const addDialogVisible = ref(false); // 控制添加账号弹窗
  203. // 表单数据
  204. const formSize = ref("default");
  205. const ruleFormRef = ref();
  206. const ruleForm = reactive({
  207. name: "",
  208. id: "",
  209. });
  210. // 表单验证
  211. const rules = reactive({
  212. name: [{ required: true, message: "分类名称不能为空", trigger: "blur" }],
  213. });
  214. // 获取账户列表
  215. const getList = async () => {
  216. loading.value = true;
  217. let params = {
  218. currentPage: currentPage.value, // 当前页
  219. pageCount: pageSize.value, // 一页数据条数
  220. userName: searchInput.userName,
  221. clubId: searchInput.clubId,
  222. isPass: searchInput.isPass,
  223. };
  224. if (searchInput.createTime) {
  225. params.startTime = searchInput.createTime[0];
  226. params.endTime = searchInput.createTime[1];
  227. }
  228. queryCategoryNewsPage(params).then((res) => {
  229. console.log(res, "获取新闻分类分页数据");
  230. if (res.code == 200) {
  231. tableData.list = res.data.list;
  232. total.value = res.data.totalCount;
  233. loading.value = false;
  234. } else {
  235. loading.value = false;
  236. }
  237. });
  238. };
  239. // 搜索功能
  240. const searchBtn = lodash.debounce(async () => {}, 300);
  241. const resetBtn = lodash.debounce(async () => {}, 300);
  242. // 添加账号
  243. const addlist = () => {
  244. dialongTitle.value = "创建分类";
  245. addDialogVisible.value = true;
  246. ruleForm.name = null;
  247. };
  248. // 添加账号
  249. const updateS = (row) => {
  250. console.log(row);
  251. dialongTitle.value = "编辑分类";
  252. addDialogVisible.value = true;
  253. ruleForm.name = row.name;
  254. ruleForm.id = row.id;
  255. };
  256. const deleteS = async (row) => {
  257. ElMessageBox.confirm("是否删除此数据?", "提示!!!", {
  258. confirmButtonText: "确认",
  259. cancelButtonText: "取消",
  260. type: "warning",
  261. })
  262. .then(async () => {
  263. let params = {
  264. id: row.id,
  265. };
  266. let res = await deleteCategoryNews(params);
  267. if (res.code == 200) {
  268. getList();
  269. ElMessage({
  270. type: "success",
  271. showClose: true,
  272. message: res.message,
  273. center: true,
  274. });
  275. } else {
  276. ElMessage({
  277. type: "error",
  278. showClose: true,
  279. message: res.message,
  280. center: true,
  281. });
  282. }
  283. })
  284. .catch(() => {
  285. loading.value = false;
  286. });
  287. };
  288. // 确认添加员工
  289. const submitAdd = lodash.debounce(async (formEl) => {
  290. if (!formEl) return;
  291. await formEl.validate(async (valid, fields) => {
  292. if (valid) {
  293. let data = {
  294. name: ruleForm.name,
  295. };
  296. let res = "";
  297. if (dialongTitle.value == "创建分类") {
  298. res = await insertCategoryNews(data);
  299. } else {
  300. data.id = ruleForm.id;
  301. res = await updateCategoryNews(data);
  302. }
  303. if (res.code == 200) {
  304. addDialogVisible.value = false;
  305. ElMessage({
  306. type: "success",
  307. showClose: true,
  308. message: res.message,
  309. center: true,
  310. });
  311. getList();
  312. } else {
  313. ElMessage({
  314. type: "error",
  315. showClose: true,
  316. message: res.message,
  317. center: true,
  318. });
  319. }
  320. } else {
  321. console.log("error submit!", fields);
  322. }
  323. });
  324. }, 1000);
  325. const cancelAdd = () => {
  326. addDialogVisible.value = false;
  327. };
  328. // 多选框功能
  329. const handleSelectionChange = (val) => {
  330. // console.log(val);
  331. selectIds.value = val.map((i) => i.id);
  332. console.log(selectIds.value);
  333. };
  334. // 表格斑马纹颜色修改
  335. const tableRowClassName = ({ row, rowIndex }) => {
  336. if (rowIndex % 2 === 0) {
  337. return "even";
  338. } else if (rowIndex % 2 !== 0) {
  339. return "odd";
  340. }
  341. return "";
  342. };
  343. // 每页显示条数
  344. const handleSizeChange = (value) => {
  345. console.log(value, "每页显示条数");
  346. pageSize.value = value;
  347. };
  348. // 分页
  349. const handleCurrentChange = (value) => {
  350. // console.log(value);
  351. currentPage.value = value;
  352. };
  353. const cancelProjectImport = () => {
  354. buildImportVisible.value = false;
  355. if (buildRef.value) {
  356. buildRef.value.clearFiles();
  357. buildFile.value = null;
  358. }
  359. };
  360. onBeforeMount(() => {
  361. getList();
  362. });
  363. onUnmounted(() => {
  364. // document.removeEventListener("keyup", Enters);
  365. });
  366. </script>
  367. <style scoped lang="scss">
  368. .scroll {
  369. width: calc(100% - 60px);
  370. height: calc(100% - 61px);
  371. margin: 0 auto;
  372. display: flex;
  373. flex-direction: column;
  374. .middle {
  375. width: calc(100%);
  376. color: #000;
  377. .filter {
  378. display: flex;
  379. flex-wrap: wrap;
  380. align-items: center;
  381. .search {
  382. margin-left: 0 !important;
  383. color: #fff;
  384. }
  385. .condition {
  386. display: flex;
  387. align-items: center;
  388. margin: 10px 30px 10px 0;
  389. :deep(.el-input .el-input__inner) {
  390. font-size: 14px;
  391. }
  392. .el-select {
  393. width: 220px;
  394. }
  395. span {
  396. margin: 0 10px 0 0;
  397. }
  398. }
  399. }
  400. .gongneng {
  401. margin: 10px 0;
  402. .el-button {
  403. color: #fff;
  404. margin-right: 15px;
  405. }
  406. }
  407. }
  408. .footer {
  409. width: calc(100%);
  410. flex: 1;
  411. margin: 0 auto;
  412. overflow: auto;
  413. .card_all {
  414. height: calc(100% - 60px);
  415. overflow: auto;
  416. // display: flex;
  417. .el-card {
  418. width: 360px !important;
  419. height: 184px;
  420. }
  421. :deep(.el-card__header) {
  422. padding: 10px 20px 0;
  423. border: 0;
  424. font-size: 20px;
  425. .card-header {
  426. display: flex;
  427. justify-content: space-between;
  428. align-items: center;
  429. font-weight: 800;
  430. .number {
  431. font-size: 26px;
  432. }
  433. }
  434. }
  435. :deep(.el-card__body) {
  436. padding: 0 20px 10px;
  437. font-size: 13px;
  438. }
  439. :deep(.el-card__footer) {
  440. padding: 10px 20px;
  441. .card-footer {
  442. display: flex;
  443. justify-content: space-around;
  444. .line {
  445. color: #ebeaea;
  446. }
  447. }
  448. }
  449. }
  450. /* WebKit 内核浏览器(Chrome、Edge、Safari)的滚动条样式 */
  451. .card_all::-webkit-scrollbar {
  452. /* 滚动条宽度 */
  453. width: 6px;
  454. height: 6px;
  455. }
  456. /* 滚动条轨道 */
  457. .card_all::-webkit-scrollbar-track {
  458. background: #f5f7fa;
  459. border-radius: 3px;
  460. }
  461. /* 滚动条滑块 */
  462. .card_all::-webkit-scrollbar-thumb {
  463. background: #c0c4cc;
  464. border-radius: 3px;
  465. /* 鼠标悬停时滑块变色 */
  466. transition: background 0.3s;
  467. }
  468. .card_all::-webkit-scrollbar-thumb:hover {
  469. background: #909399;
  470. }
  471. .pageSize {
  472. display: flex;
  473. align-items: center;
  474. justify-content: space-between;
  475. margin: 0 30px;
  476. height: 60px;
  477. span {
  478. color: #000;
  479. }
  480. .el-pagination {
  481. // width: 1600px;
  482. :deep(.el-pagination__total) {
  483. color: #000;
  484. }
  485. :deep(.el-pagination__goto) {
  486. color: #000;
  487. }
  488. :deep(.el-pagination__classifier) {
  489. color: #000;
  490. }
  491. :deep(.el-input__wrapper) {
  492. border: 1px solid rgba(0, 0, 0, 1);
  493. border-radius: 5px;
  494. box-shadow: none;
  495. }
  496. :deep(.el-pager li) {
  497. margin: 0 5px;
  498. border: 1px solid rgba(0, 0, 0, 1);
  499. border-radius: 5px;
  500. background-color: transparent;
  501. }
  502. :deep(.el-pager li.is-active) {
  503. // background-color: rgba(0, 97, 255, 0.8);
  504. border: 1px solid rgba(0, 97, 255, 1);
  505. color: rgba(0, 97, 255, 1);
  506. }
  507. :deep(.btn-prev) {
  508. margin-right: 5px;
  509. border: 1px solid rgba(0, 0, 0, 1);
  510. border-radius: 5px;
  511. background-color: transparent;
  512. }
  513. :deep(.btn-next) {
  514. margin-left: 5px;
  515. border: 1px solid rgba(0, 0, 0, 1);
  516. border-radius: 5px;
  517. background-color: transparent;
  518. }
  519. }
  520. }
  521. }
  522. }
  523. // 添加员工弹窗样式
  524. .addStaff {
  525. .options {
  526. // border: 1px solid red;
  527. margin-top: 40px;
  528. }
  529. }
  530. </style>