index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="模板名称" prop="tmplName">
  5. <el-input
  6. v-model="queryParams.tmplName"
  7. placeholder="请输入模板名称"
  8. clearable
  9. @keyup.enter="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="创建人" prop="createBy">
  13. <el-input
  14. v-model="queryParams.createBy"
  15. placeholder="请输入创建人"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="创建时间" prop="createTime">
  21. <el-date-picker clearable
  22. v-model="queryParams.createTime"
  23. type="date"
  24. value-format="YYYY-MM-DD"
  25. placeholder="请选择创建时间">
  26. </el-date-picker>
  27. </el-form-item>
  28. <el-form-item label="更新人" prop="updateBy">
  29. <el-input
  30. v-model="queryParams.updateBy"
  31. placeholder="请输入更新人"
  32. clearable
  33. @keyup.enter="handleQuery"
  34. />
  35. </el-form-item>
  36. <el-form-item label="更新时间" prop="updateTime">
  37. <el-date-picker clearable
  38. v-model="queryParams.updateTime"
  39. type="date"
  40. value-format="YYYY-MM-DD"
  41. placeholder="请选择更新时间">
  42. </el-date-picker>
  43. </el-form-item>
  44. <el-form-item>
  45. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  46. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  47. </el-form-item>
  48. </el-form>
  49. <el-row :gutter="10" class="mb8">
  50. <el-col :span="1.5">
  51. <el-button
  52. type="primary"
  53. plain
  54. icon="Plus"
  55. @click="handleAdd"
  56. v-hasPermi="['biz:dirTemplate:add']"
  57. >新增
  58. </el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="success"
  63. plain
  64. icon="Edit"
  65. :disabled="single"
  66. @click="handleUpdate"
  67. v-hasPermi="['biz:dirTemplate:edit']"
  68. >修改
  69. </el-button>
  70. </el-col>
  71. <el-col :span="1.5">
  72. <el-button
  73. type="danger"
  74. plain
  75. icon="Delete"
  76. :disabled="multiple"
  77. @click="handleDelete"
  78. v-hasPermi="['biz:dirTemplate:remove']"
  79. >删除
  80. </el-button>
  81. </el-col>
  82. <el-col :span="1.5">
  83. <el-button
  84. type="warning"
  85. plain
  86. icon="Download"
  87. @click="handleExport"
  88. v-hasPermi="['biz:dirTemplate:export']"
  89. >导出
  90. </el-button>
  91. </el-col>
  92. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  93. </el-row>
  94. <el-table v-loading="loading" :data="dirTemplateList" @selection-change="handleSelectionChange">
  95. <el-table-column type="selection" width="55" align="center"/>
  96. <el-table-column label="模板ID" align="center" prop="tmplId"/>
  97. <el-table-column label="模板名称" align="center" prop="tmplName"/>
  98. <el-table-column label="创建人" align="center" prop="createBy"/>
  99. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  100. <template #default="scope">
  101. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="更新人" align="center" prop="updateBy"/>
  105. <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
  106. <template #default="scope">
  107. <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="备注" align="center" prop="remark"/>
  111. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  112. <template #default="scope">
  113. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
  114. v-hasPermi="['biz:dirTemplate:edit']">修改
  115. </el-button>
  116. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
  117. v-hasPermi="['biz:dirTemplate:remove']">删除
  118. </el-button>
  119. </template>
  120. </el-table-column>
  121. </el-table>
  122. <pagination
  123. v-show="total>0"
  124. :total="total"
  125. v-model:page="queryParams.pageNum"
  126. v-model:limit="queryParams.pageSize"
  127. @pagination="getList"
  128. />
  129. <!-- 添加或修改目录模板对话框 -->
  130. <el-dialog :title="title" v-model="open" width="500px" append-to-body @close="cancelAddTemp">
  131. <el-form ref="dirTemplateRef" :model="form" :rules="rules" label-width="80px">
  132. <el-form-item label="模板名称" prop="tmplName">
  133. <el-input v-model="tempTitle" placeholder="请输入模板名称"/>
  134. </el-form-item>
  135. <el-form-item label="模板内容" prop="tmplContent">
  136. <el-tree
  137. :data="tempData"
  138. default-expand-all
  139. node-key="id"
  140. style="width:100%;height:300px;overflow-y: auto;"
  141. :expand-on-click-node="false"
  142. >
  143. <template #default="{ node, data }">
  144. <span class="custom-tree-node">
  145. <span>{{ node.label }}</span>
  146. <span>
  147. <a class="btm" @click="append(data)"> 增加 </a>
  148. <a class="btm" v-if="data.id != 1" @click="updataNode(data)"> 修改 </a>
  149. <a class="btm" v-if="data.id != 1" style="margin-left: 8px" @click="remove(node, data)"> 删除 </a>
  150. </span>
  151. </span>
  152. </template>
  153. </el-tree>
  154. </el-form-item>
  155. <el-form-item label="备注" prop="remark">
  156. <el-input v-model="form.remark" placeholder="请输入备注"/>
  157. </el-form-item>
  158. </el-form>
  159. <template #footer>
  160. <div class="dialog-footer">
  161. <el-button type="primary" @click="submitForm">确 定</el-button>
  162. <el-button @click="cancelAddTemp">取 消</el-button>
  163. </div>
  164. </template>
  165. </el-dialog>
  166. <el-dialog title="目录名称" v-model="showMenuName" width="500px">
  167. <el-input v-model="newName" maxlength="32" placeholder="请输入目录名称"/>
  168. <template #footer>
  169. <div class="dialog-footer">
  170. <el-button type="primary" @click="submitMenuName">确 定</el-button>
  171. <el-button @click="cancelMenuName">取 消</el-button>
  172. </div>
  173. </template>
  174. </el-dialog>
  175. </div>
  176. </template>
  177. <script setup name="DirTemplate">
  178. import {
  179. addDirTemplate,
  180. delDirTemplate,
  181. getDirTemplate,
  182. listDirTemplate,
  183. updateDirTemplate
  184. } from "@/api/biz/dirTemplate";
  185. import { ElMessage} from 'element-plus'
  186. const {proxy} = getCurrentInstance();
  187. const dirTemplateList = ref([]);
  188. const open = ref(false);
  189. const loading = ref(true);
  190. const showSearch = ref(true);
  191. const ids = ref([]);
  192. const single = ref(true);
  193. const multiple = ref(true);
  194. const total = ref(0);
  195. const title = ref("");
  196. const showMenuName = ref(false)
  197. const newName = ref()
  198. const tempId = ref(1000)
  199. const upNodeData = ref()
  200. const tempTitle = ref('')
  201. const tempData = ref([
  202. {id:1,label:tempTitle || '请输入模板名称',children:[
  203. ]}
  204. ])
  205. const data = reactive({
  206. form: {},
  207. queryParams: {
  208. pageNum: 1,
  209. pageSize: 10,
  210. tmplName: null,
  211. createBy: null,
  212. createTime: null,
  213. updateBy: null,
  214. updateTime: null,
  215. },
  216. rules: {}
  217. });
  218. const {queryParams, form, rules} = toRefs(data);
  219. /** 查询目录模板列表 */
  220. function getList() {
  221. loading.value = true;
  222. listDirTemplate(queryParams.value).then(response => {
  223. dirTemplateList.value = response.rows;
  224. total.value = response.total;
  225. loading.value = false;
  226. });
  227. }
  228. // 取消按钮
  229. function cancel() {
  230. open.value = false;
  231. reset();
  232. }
  233. // 表单重置
  234. function reset() {
  235. form.value = {
  236. tmplId: null,
  237. tmplName: null,
  238. tmplContent: null,
  239. createBy: null,
  240. createTime: null,
  241. updateBy: null,
  242. updateTime: null,
  243. remark: null
  244. };
  245. proxy.resetForm("dirTemplateRef");
  246. }
  247. /** 搜索按钮操作 */
  248. function handleQuery() {
  249. queryParams.value.pageNum = 1;
  250. getList();
  251. }
  252. /** 重置按钮操作 */
  253. function resetQuery() {
  254. proxy.resetForm("queryRef");
  255. handleQuery();
  256. }
  257. // 多选框选中数据
  258. function handleSelectionChange(selection) {
  259. ids.value = selection.map(item => item.tmplId);
  260. single.value = selection.length != 1;
  261. multiple.value = !selection.length;
  262. }
  263. /** 新增按钮操作 */
  264. function handleAdd() {
  265. reset();
  266. open.value = true;
  267. title.value = "添加目录模板";
  268. }
  269. /** 修改按钮操作 */
  270. function handleUpdate(row) {
  271. reset();
  272. const _tmplId = row.tmplId || ids.value
  273. getDirTemplate(_tmplId).then(response => {
  274. console.log('response',response);
  275. form.value = response.data;
  276. const arr = JSON.parse(response.data.tmplContent)
  277. const getNewtempId = (arr)=>{
  278. arr.map(item=>{
  279. if(item.id >= tempId.value){
  280. console.log('1',item.id);
  281. tempId.value = item.id +1
  282. }
  283. if(item.children?.length>0){
  284. getNewtempId(item.children)
  285. }
  286. })
  287. }
  288. getNewtempId(arr)
  289. tempTitle.value = response.data.tmplName
  290. tempData.value = [{id:1,label:tempTitle,children:[]}]
  291. tempData.value[0].children = arr
  292. open.value = true;
  293. title.value = "修改目录模板";
  294. });
  295. }
  296. /** 提交按钮 */
  297. function submitForm() {
  298. proxy.$refs["dirTemplateRef"].validate(valid => {
  299. if(!tempTitle.value){
  300. return ElMessage({
  301. message: "模板名不能为空",
  302. type: "error"
  303. })
  304. }
  305. const str = JSON.stringify(tempData.value[0].children)
  306. form.value.tmplContent = str
  307. form.value.tmplName = tempTitle.value
  308. if (valid) {
  309. if (form.value.tmplId != null) {
  310. updateDirTemplate(form.value).then(response => {
  311. proxy.$modal.msgSuccess("修改成功");
  312. open.value = false;
  313. getList();
  314. });
  315. } else {
  316. addDirTemplate(form.value).then(response => {
  317. proxy.$modal.msgSuccess("新增成功");
  318. open.value = false;
  319. getList();
  320. });
  321. }
  322. }
  323. });
  324. }
  325. /** 删除按钮操作 */
  326. function handleDelete(row) {
  327. const _tmplIds = row.tmplId || ids.value;
  328. proxy.$modal.confirm('是否确认删除目录模板编号为"' + _tmplIds + '"的数据项?').then(function () {
  329. return delDirTemplate(_tmplIds);
  330. }).then(() => {
  331. getList();
  332. proxy.$modal.msgSuccess("删除成功");
  333. }).catch(() => {
  334. });
  335. }
  336. /** 导出按钮操作 */
  337. function handleExport() {
  338. proxy.download('biz/dirTemplate/export', {
  339. ...queryParams.value
  340. }, `dirTemplate_${new Date().getTime()}.xlsx`)
  341. }
  342. // 新增目录节点
  343. const append = (data)=>{
  344. // console.log('data',data);
  345. const newChild = {id: tempId.value, label: 'newMenu', children: [] }
  346. tempId.value = tempId.value+1
  347. if (!data.children) {
  348. data.children = []
  349. }
  350. data.children.push(newChild)
  351. tempData.value = [...tempData.value]
  352. }
  353. // 移除目录节点
  354. const remove = (node, data)=>{
  355. const parent = node.parent
  356. const children = parent.data.children || parent.data
  357. const index = children.findIndex((d) => d.id === data.id)
  358. children.splice(index, 1)
  359. tempData.value = [...tempData.value]
  360. }
  361. // 修改目录节点
  362. const updataNode = (data)=>{
  363. newName.value = ''
  364. newName.value = data.label
  365. showMenuName.value = true
  366. upNodeData.value = data
  367. }
  368. const submitMenuName = ()=>{
  369. if(!newName.value){
  370. return ElMessage({
  371. message: "目录名不能为空",
  372. type: "error"
  373. })
  374. }
  375. const oldArr = tempData.value
  376. const getNewData = (data)=>{
  377. data.map(item=>{
  378. if(item.id == upNodeData.value.id){
  379. // console.log(1);
  380. item.label = newName.value
  381. return
  382. }
  383. if(item.children?.length>0){
  384. getNewData(item.children)
  385. }
  386. })
  387. }
  388. getNewData(oldArr)
  389. tempData.value= JSON.parse(JSON.stringify(oldArr))
  390. setTimeout(() => {
  391. showMenuName.value = false
  392. // console.log('tempData.value',tempData.value);
  393. // console.log('upNodeData.value',upNodeData.value);
  394. }, 200);
  395. }
  396. const submitAddTemp = ()=>{
  397. }
  398. const cancelMenuName = ()=>{
  399. newName.value = ''
  400. showMenuName.value = false
  401. }
  402. const cancelAddTemp = ()=>{
  403. open.value = false
  404. newName.value = ''
  405. tempTitle.value = ''
  406. tempData.value = [
  407. {id:1,label:tempTitle || '请输入模板名称',children:[
  408. ]}
  409. ]
  410. }
  411. getList();
  412. </script>
  413. <style lang="scss" scoped>
  414. .custom-tree-node {
  415. width: 100%;
  416. flex: 1;
  417. display: flex;
  418. align-items: center;
  419. justify-content: space-between;
  420. font-size: 14px;
  421. padding-right: 8px;
  422. }
  423. .btm{
  424. color: skyblue;
  425. }
  426. </style>