index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. <template>
  2. <div class="tenant">
  3. <byTable
  4. :source="sourceList.data"
  5. :pagination="sourceList.pagination"
  6. :config="config"
  7. :loading="loading"
  8. highlight-current-row
  9. :selectConfig="selectConfig"
  10. :table-events="{
  11. select: select,
  12. }"
  13. :action-list="[
  14. {
  15. text: '添加栏目菜单',
  16. action: () => openModal('add'),
  17. },
  18. ]"
  19. @get-list="getList">
  20. <template #listType="{ item }">
  21. {{ getCellColumn(item) }}
  22. </template>
  23. </byTable>
  24. <el-dialog z-index="100" :title="modalType == 'add' ? '添加栏目菜单' : '编辑栏目菜单'" v-if="dialogVisible" v-model="dialogVisible" width="600" v-loading="loading">
  25. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform">
  26. <template #subColumn>
  27. <el-row style="width: 100%;margin-bottom: 10px" v-for="(row, index) in formData.data.columnMenuSubList" ref="sort">
  28. <el-col :span="7" >
  29. <el-form-item
  30. :prop="'columnMenuSubList.' + index + '.name'"
  31. :rules="rules.subName"
  32. prop="name"
  33. style="margin: 8px 0 8px 0">
  34. <el-input v-model="row.name" placeholder="请输入子栏目" :controls="false" />
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="6" >
  38. <el-form-item
  39. :prop="'columnMenuSubList.' + index + '.status'"
  40. :rules="rules.subStatus" style="margin-left: 8px;transform: translateY(8px)"
  41. prop="status">
  42. <el-select v-model="row.status" placeholder="请选择状态" >
  43. <el-option v-for="item in enableStatus" :key="item.value" :label="item.label" :value="item.value" />
  44. </el-select>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="6" >
  48. <el-form-item
  49. :prop="'columnMenuSubList.' + index + '.sort'"
  50. :rules="rules.subSort" style="margin-left: 8px;transform: translateY(8px)"
  51. prop="sort">
  52. <el-input-number v-model="row.sort" placeholder="请输入排序" :precision="0" :max="999" :min="0" />
  53. </el-form-item>
  54. </el-col>
  55. <el-col :span="5" >
  56. <el-icon style="margin-left: 8px; color: red; cursor: pointer; transform: translateY(10px)" @click="clickDelete(index)"><Delete /></el-icon>
  57. </el-col>
  58. </el-row>
  59. <el-row style="width: 100%">
  60. <el-row>
  61. <el-button type="primary" @click="clickAddSubColumn()">添加</el-button>
  62. </el-row>
  63. </el-row>
  64. </template>
  65. <template #detailsContent>
  66. <div style="width: 100%" v-if="dialogVisible">
  67. <TinymceEditor
  68. :value="formData.data.content"
  69. @updateValue="updateHandover"
  70. ref="contentEditor"
  71. />
  72. </div>
  73. </template>
  74. </byForm>
  75. <template #footer>
  76. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  77. <el-button type="primary" v-no-double-click="submitForm" size="large" :loading="submitLoading">确 定</el-button>
  78. </template>
  79. </el-dialog>
  80. </div>
  81. </template>
  82. <script setup>
  83. import { ElMessage, ElMessageBox } from "element-plus";
  84. import byTable from "@/components/byTable/index";
  85. import byForm from "@/components/byForm/index";
  86. import {computed, nextTick, reactive, ref} from "vue";
  87. import TinymceEditor from "@/components/Editor/TinymceEditor.vue";
  88. import {getDictOneByXmhjc, getFileList,getFileStr} from "@/api/XMHJC/common";
  89. import {
  90. addColumnMenu, checkDeleteColumnMenuSub, deleteColumnMenu,
  91. editColumnMenu, findColumnArticleList,
  92. findColumnMenuList,
  93. getColumnMenu
  94. } from "@/api/XMHJC/column";
  95. import {isNullOrUndefined} from "@tinymce/tinymce-vue/lib/es2015/main/ts/Utils";
  96. const loading = ref(false);
  97. const submitLoading = ref(false);
  98. const sourceList = ref({
  99. data: [],
  100. pagination: {
  101. total: 0,
  102. pageNum: 1,
  103. pageSize: 10,
  104. },
  105. });
  106. let dialogVisible = ref(false);
  107. let modalType = ref("add");
  108. let rules = ref({
  109. name: [{ required: true, message: "请输入企业文化标题", trigger: "blur" }],
  110. status: [{ required: true, message: "请选择启用状态", trigger: "change" }],
  111. subStatus: [{ required: true, message: "请选择启用状态", trigger: "change" }],
  112. type: [{ required: true, message: "请选择跳转类型", trigger: "change" }],
  113. listType: [{ required: true, message: "请选择列表类型", trigger: "change" }],
  114. isRelated: [{ required: true, message: "请选择是否开启", trigger: "change" }],
  115. url: [{ required: true, message: "请输入第三方链接", trigger: "blur" }],
  116. sort: [{ required: true, message: "请输入排序", trigger: "blur" }],
  117. subName: [{ required: true, message: "请输入子栏目", trigger: "blur" }],
  118. subSort: [{ required: true, message: "请输入排序", trigger: "blur" }],
  119. });
  120. const { proxy } = getCurrentInstance();
  121. const columnType = ref([]);
  122. const columListType = ref([]);
  123. const enableStatus = ref([]);
  124. const selectConfig = [];
  125. const config = computed(() => {
  126. return [
  127. {
  128. attrs: {
  129. label: "栏目名称",
  130. prop: "name",
  131. },
  132. },
  133. {
  134. attrs: {
  135. label: "栏目类型",
  136. prop: "type",
  137. },
  138. render(type) {
  139. return proxy.dictValueLabel(type, columnType.value);
  140. },
  141. },
  142. {
  143. attrs: {
  144. label: "列表类型",
  145. prop: "listType",
  146. slot: 'listType',
  147. },
  148. },
  149. {
  150. attrs: {
  151. label: "状态",
  152. prop: "status",
  153. width: '80'
  154. },
  155. render(type) {
  156. return proxy.dictValueLabel(type, enableStatus.value);
  157. },
  158. },
  159. {
  160. attrs: {
  161. label: "排序",
  162. prop: "sort",
  163. width: '80'
  164. },
  165. },
  166. {
  167. attrs: {
  168. label: "操作",
  169. width: "120",
  170. align: "right",
  171. },
  172. renderHTML(row) {
  173. return [
  174. {
  175. attrs: {
  176. label: "修改",
  177. type: "primary",
  178. text: true,
  179. },
  180. el: "button",
  181. click() {
  182. getDtl(row);
  183. },
  184. },
  185. {
  186. attrs: {
  187. label: "删除",
  188. type: "danger",
  189. text: true,
  190. },
  191. el: "button",
  192. click() {
  193. ElMessageBox.confirm("此操作将永久删除该数据, 是否继续?", "提示", {
  194. confirmButtonText: "确定",
  195. cancelButtonText: "取消",
  196. type: "warning",
  197. }).then(() => {
  198. deleteColumnMenu({
  199. id: row.id,
  200. })
  201. .then((res) => {
  202. ElMessage({
  203. message: "删除成功",
  204. type: "success",
  205. });
  206. getList();
  207. });
  208. });
  209. },
  210. },
  211. ];
  212. },
  213. },
  214. ];
  215. });
  216. let formData = reactive({
  217. data: {
  218. columnMenuSubList:[],
  219. },
  220. });
  221. const formOption = reactive({
  222. inline: true,
  223. labelWidth: 100,
  224. itemWidth: 100,
  225. rules: [],
  226. });
  227. const byform = ref(null);
  228. const formConfig = computed(() => {
  229. return [
  230. {
  231. type: "input",
  232. prop: "name",
  233. label: "栏目名称",
  234. required: true,
  235. },
  236. {
  237. type: "select",
  238. prop: "type",
  239. label: "栏目类型",
  240. data: columnType.value,
  241. required: true,
  242. },
  243. {
  244. type: "select",
  245. prop: "isRelated",
  246. label: "是否开启相关文章",
  247. data: enableStatus.value,
  248. required: true,
  249. isShow: formData.data.type == "1"
  250. },
  251. {
  252. type: "slot",
  253. slotName: "subColumn",
  254. prop: "subColumn",
  255. label: "子栏目",
  256. isShow: formData.data.type == "1"
  257. },
  258. {
  259. type: "select",
  260. prop: "listType",
  261. label: "列表类型",
  262. data: columListType.value,
  263. required: true,
  264. isShow: formData.data.type == "1"
  265. },
  266. {
  267. type: "slot",
  268. slotName: "detailsContent",
  269. prop: "detailsContent",
  270. label: "详情内容",
  271. isShow: formData.data.type == "2"
  272. },
  273. {
  274. type: "input",
  275. prop: "url",
  276. label: "第三方链接",
  277. required: true,
  278. isShow: formData.data.type == "3"
  279. },
  280. {
  281. label: "启用状态",
  282. prop: "status",
  283. type: "select",
  284. data: enableStatus.value,
  285. required: true,
  286. },
  287. {
  288. type: "input",
  289. prop: "sort",
  290. label: "排序",
  291. itemType: "number",
  292. precision: 0,
  293. max: 999,
  294. required: true,
  295. },
  296. ];
  297. });
  298. const getDictlist = async () => {
  299. const res = await getDictOneByXmhjc(["column_type","enable_status","column_list_type"]);
  300. columnType.value = res["column_type"].map((x) => ({
  301. label: x.dictValue,
  302. value: x.dictKey,
  303. }));
  304. enableStatus.value = res["enable_status"].map((x) => ({
  305. label: x.dictValue,
  306. value: x.dictKey,
  307. }));
  308. columListType.value = res["column_list_type"].map((x) => ({
  309. label: x.dictValue,
  310. value: x.dictKey,
  311. }));
  312. };
  313. const getList = async (req) => {
  314. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  315. loading.value = true;
  316. const res = await findColumnMenuList(sourceList.value.pagination);
  317. sourceList.value.data = res.data.rows;
  318. sourceList.value.pagination.total = res.data.total;
  319. setTimeout(() => {
  320. loading.value = false;
  321. }, 200);
  322. };
  323. const openModal = () => {
  324. dialogVisible.value = true;
  325. modalType.value = "add";
  326. formData.data = {
  327. content:'',
  328. columnMenuSubList:[],
  329. };
  330. };
  331. const selection = ref({
  332. data: [],
  333. });
  334. const select = (_selection, row) => {
  335. selection.value.data = _selection;
  336. };
  337. const submitForm = () => {
  338. byform.value.handleSubmit(() => {
  339. if (!(formData.data.columnMenuSubList && formData.data.columnMenuSubList.length > 0)) {
  340. // formData.data.columnMenuSubList = [];
  341. ElMessage({message: "请填写子栏目",type: "error",});
  342. return
  343. }
  344. if (formData.data.type == '2' &&
  345. !formData.data.content) {
  346. ElMessage({message: "请填写详情内容",type: "error",});
  347. return
  348. }
  349. submitLoading.value = true;
  350. if (modalType.value === 'add'){
  351. addColumnMenu(formData.data).then(response => {
  352. ElMessage({
  353. message: "添加成功",
  354. type: "success",
  355. });
  356. dialogVisible.value = false;
  357. submitLoading.value = false;
  358. getList();
  359. }).catch(()=>{
  360. submitLoading.value = false;
  361. });
  362. }else {
  363. editColumnMenu(formData.data).then(response => {
  364. ElMessage({
  365. message: "编辑成功",
  366. type: "success",
  367. });
  368. dialogVisible.value = false;
  369. submitLoading.value = false;
  370. getList();
  371. }).catch(()=>{
  372. submitLoading.value = false;
  373. });
  374. }
  375. });
  376. };
  377. const getDtl = async (row) => {
  378. modalType.value = "edit";
  379. const response = await getColumnMenu({ id: row.id })
  380. formData.data = response.data;
  381. dialogVisible.value = true;
  382. };
  383. const updateHandover = (val) => {
  384. formData.data.content = val;
  385. };
  386. const clickAddSubColumn = () => {
  387. if (formData.data.columnMenuSubList && formData.data.columnMenuSubList.length > 0) {
  388. const sort = formData.data.columnMenuSubList[formData.data.columnMenuSubList.length-1].sort
  389. formData.data.columnMenuSubList.push({
  390. name: "",
  391. sort: sort+10,
  392. });
  393. } else {
  394. formData.data.columnMenuSubList = [
  395. {
  396. name: "",
  397. sort: 10,
  398. },
  399. ];
  400. }
  401. };
  402. const getCellColumn = (row) =>{
  403. if (row.type != '1'){
  404. return "——"
  405. }else {
  406. const label = columListType.value.filter( (x) => {
  407. if (x.value == row.listType){
  408. return true
  409. }
  410. return false
  411. })
  412. return label.length > 0 ? label[0].label:'';
  413. }
  414. }
  415. const clickDelete = async (index) => {
  416. console.log(isNullOrUndefined(formData.data.columnMenuSubList[index].id))
  417. if (isNullOrUndefined(formData.data.columnMenuSubList[index].id)){
  418. formData.data.columnMenuSubList.splice(index, 1);
  419. }else {
  420. //验证是否能删除该子栏目
  421. const res = await checkDeleteColumnMenuSub({id : formData.data.columnMenuSubList[index].id });
  422. if (res.data){
  423. formData.data.columnMenuSubList.splice(index, 1);
  424. return
  425. }else {
  426. ElMessage({message: "该栏目存在文章,删除失败!如不想显示请禁用",type: "error",});
  427. return
  428. }
  429. }
  430. };
  431. const getArticleList = async () => {
  432. const res = await findColumnArticleList({
  433. pageNum: 1,
  434. pageSize: 99999,
  435. status: 1,
  436. });
  437. articleList.value = res.data.rows.map((x) => ({
  438. label: x.title,
  439. value: x.id,
  440. }));
  441. };
  442. getDictlist()
  443. getList()
  444. </script>
  445. <style lang="scss" scoped>
  446. .tenant {
  447. padding: 20px;
  448. .delete-btn{
  449. margin-top: 10px;
  450. margin-left: 25px;
  451. }
  452. }
  453. .avatar-uploader .avatar {
  454. width: 110px;
  455. height: 110px;
  456. display: block;
  457. background-color: black;
  458. }
  459. .avatar-uploader .el-upload {
  460. border: 1px dashed var(--el-border-color);
  461. border-radius: 6px;
  462. cursor: pointer;
  463. position: relative;
  464. overflow: hidden;
  465. transition: var(--el-transition-duration-fast);
  466. }
  467. .avatar-uploader .el-upload:hover {
  468. border-color: var(--el-color-primary);
  469. }
  470. .el-icon.avatar-uploader-icon {
  471. font-size: 28px;
  472. color: #8c939d;
  473. width: 110px;
  474. height: 110px;
  475. text-align: center;
  476. border: 1px dashed var(--el-border-color);
  477. }
  478. </style>