当前位置: 首页 > news >正文

网站开发招标免费seo网站自动推广软件

网站开发招标,免费seo网站自动推广软件,pc端微信端网站建设,微信怎么开店铺小程序文章目录 tree-selector1. 新增表单组件2. 在父组件中引用3. 父组件添加新增按钮4. 树形组件4.1 前端代码4.2 后端代码 前言:最近写项目,发现了一些很有意思的功能,想写文章,录视频把这些内容记录下。但这些功能太零碎&#xff0c…

文章目录

    • tree-selector
      • 1. 新增表单组件
      • 2. 在父组件中引用
      • 3. 父组件添加新增按钮
      • 4. 树形组件
        • 4.1 前端代码
        • 4.2 后端代码

前言:最近写项目,发现了一些很有意思的功能,想写文章,录视频把这些内容记录下。但这些功能太零碎,如果为每个功能都单独搭建一个项目,这明显不合适。于是我想,就搭建一个项目,把那些我想将的小功能全部整合到一起。实现 搭一次环境,处处使用。

本文主要实现一下两个功能

  1. 新增表单, 更新表单组件编写
  2. treeSelect树形结构编写

环境搭建
文章链接

已录制视频
视频链接

tree-selector

这个功能是table-tree功能的附属产品。是为了能在新增表单中,更方便选择上级节点所开发的功能。因此,我们得先把新增表单组件开发出来

新增、修改逻辑
在这里插入图片描述

tree形组件

在这里插入图片描述

1. 新增表单组件

/src/views/welcome/treeAddOrUpdate.vue

<script setup lang="ts">
import { UnitEntity } from "@/api/tree";
import { ref, reactive } from "vue";
const dialogVisible = ref(false);let form = reactive(new UnitEntity());
const title = ref("新增表单");// 定义init方法, 让父组件调用
const init = data => {console.log(data);if (data) {form = data;title.value = "编辑表单";} else {title.value = "新增表单";}dialogVisible.value = true;
};// 暴露方法
defineExpose({ init });// 提交表单
const submit = () => {console.log(form);
};
</script><template><el-dialog v-model="dialogVisible" :title="title"><el-form :model="form"><el-form-item label="单元"><el-input v-model="form.unit" /></el-form-item><el-form-item label="父id"><el-input v-model="form.pid" /></el-form-item></el-form><el-button @click="submit">提交</el-button></el-dialog>
</template><style lang="scss" scoped></style>

2. 在父组件中引用

/src/views/welcome/index.vue

<script setup lang="ts">
import { ref, onMounted, nextTick } from "vue";
import TreeAddOrUpdate from "./treeAddOrUpdate.vue";const dialogVisible = ref(false);// 引用子组件
const treeAddOrUpdateRef = ref();// ...
</script><template><!--ref引用组件--><tree-add-or-update v-if="dialogVisible" ref="treeAddOrUpdateRef" />
</template>

3. 父组件添加新增按钮

/src/views/welcome/index.vue

<script setup lang="ts">
// 新增/修改 都可以使用该方法
const addOrUpdate = data => {console.log(data);dialogVisible.value = true;// nextTick保证treeAddOrUpdateRef能够引用到子组件nextTick(() => {// 调用子组件暴露的init方法, 设置数据treeAddOrUpdateRef.value.init(data);});
};
</script><template><el-button type="primary" @click="addOrUpdate">新增</el-button>
</template>

完成以上步骤,我们就可以点击新增表单,但这个界面对于用户来说其实并不美好。谁知道父id是什么?因此我们采用tree-select的形式来提高界面的可使用性

4. 树形组件

在这里插入图片描述

我们使用的是element plus的TreeSelect组件,具体文档如下:[TreeSelect 树形选择 | Element Plus (element-plus.org)]()

4.1 前端代码
  • /src/api/tree.ts
export class LabelVo {
id: Number;
label: String;
value: String;
children: Array<LabelVo>;
}/** 获取全部的treeLabel */
export const getLabelTree = () => {
return http.request<R<Array<LabelVo>>>("get",baseUrlApi("unit/listTreeSelect")
);
};/** 根据id查询节点 */
export const getNodeById = (id: Number) => {
return http.request<R<LabelVo>>("get", baseUrlApi(`unit/listNode?id=${id}`));
};
  • /src/views/welcome/treeAddOrUpdate.vue
<template>
<el-tree-selectv-model="value":data="data"check-strictlyshow-checkbox@check-change="handleCheckChange"style="width: 240px"/>
</template><script>
// 定义init方法, 让父组件调用
const init = data => {console.log(data);if (data) {form = data;title.value = "编辑表单";// 查询上级节点数据(根据id返回{value, label, id})getNodeById(form.pid).then(res => {if (res.code === 0) {value.value = res.data.value;}});} else {title.value = "新增表单";}console.log(form);dialogVisible.value = true;
};const value = ref();
const data = ref<Array<LabelVo>>();const handleCheckChange = (data: LabelVo, checked, indeterminate) => {console.log(data);console.log(checked);if (checked) {form.pid = data.id;}
};
</script>

tip: init方法改动

4.2 后端代码
  • 定义实体类
package com.fgbg.demo.vo;import lombok.Data;import java.util.List;@Data
public class LabelVo {private String label;private String value;private Integer id;private Integer pid;private List<LabelVo> children;
}
  • 返回tree-selector展示所需数据

        @RequestMapping("/listTreeSelect")public R listTreeSelect() {List<TbUnit> tbUnitList = unitService.list();List<LabelVo> list = tbUnitList.stream().map(e -> {LabelVo vo = new LabelVo();vo.setValue(e.getUnit());vo.setLabel(e.getUnit());vo.setId(e.getId());vo.setPid(e.getPid());return vo;}).collect(Collectors.toList());// TbUnit -> LabelVo// 建立map映射(id->index)HashMap<Integer, Integer> map = new HashMap<>();for (int index = 0; index < list.size(); index++) {Integer id = list.get(index).getId();map.put(id, index);}// ...for (int i = 0; i < list.size(); i++) {LabelVo node = list.get(i);Integer pid = node.getPid();// 有父亲if (pid != null) {// 找到pid的父亲, 并把当前节点(node)添加到父亲节点的children里面Integer indexParent = map.get(pid);// 获取父亲节点LabelVo parent = list.get(indexParent);if (parent.getChildren() == null) {parent.setChildren(new ArrayList<>());}// 向父亲节点的children字段添加当前nodeparent.getChildren().add(node);}}// 过滤出一级节点List<LabelVo> ans = list.stream().filter(e -> e.getPid() == null).collect(Collectors.toList());return R.ok().put("data", ans);}
  • 根据id查询数据

        // 根据id查询节点数据{value id label}@RequestMapping("/listNode")public R listNode(@RequestParam Integer id) {TbUnit unit = unitService.getById(id);LabelVo labelVo = new LabelVo();labelVo.setLabel(unit.getUnit());labelVo.setValue(unit.getUnit());labelVo.setId(unit.getId());return R.ok().put("data", labelVo);}
    

文章转载自:
http://dinnconutgall.stkw.cn
http://dinncostratal.stkw.cn
http://dinncounlanguaged.stkw.cn
http://dinncoautoecious.stkw.cn
http://dinncohirsutulous.stkw.cn
http://dinncotortoise.stkw.cn
http://dinncodeaminize.stkw.cn
http://dinncocanned.stkw.cn
http://dinncocrag.stkw.cn
http://dinncosuperaqueous.stkw.cn
http://dinncocounterplan.stkw.cn
http://dinncoportuguese.stkw.cn
http://dinncoelaborator.stkw.cn
http://dinncoplayer.stkw.cn
http://dinncooligophagous.stkw.cn
http://dinncoheteroplasy.stkw.cn
http://dinncotops.stkw.cn
http://dinncofulgurating.stkw.cn
http://dinncodetest.stkw.cn
http://dinncoinswept.stkw.cn
http://dinncocords.stkw.cn
http://dinncocatbird.stkw.cn
http://dinncoinflicter.stkw.cn
http://dinncosemiclassic.stkw.cn
http://dinncotwenty.stkw.cn
http://dinncoabusive.stkw.cn
http://dinncohereinabove.stkw.cn
http://dinncosurf.stkw.cn
http://dinncoantirust.stkw.cn
http://dinncoconversant.stkw.cn
http://dinncocompulsorily.stkw.cn
http://dinncoentice.stkw.cn
http://dinncofreestyle.stkw.cn
http://dinncoantiworld.stkw.cn
http://dinncozenithward.stkw.cn
http://dinncotunnel.stkw.cn
http://dinncodossier.stkw.cn
http://dinncofibster.stkw.cn
http://dinncoanion.stkw.cn
http://dinncobroach.stkw.cn
http://dinncocolicky.stkw.cn
http://dinncope.stkw.cn
http://dinncochlorocarbon.stkw.cn
http://dinncocistus.stkw.cn
http://dinncojuju.stkw.cn
http://dinncofurl.stkw.cn
http://dinncodocumentation.stkw.cn
http://dinncointercommunicate.stkw.cn
http://dinncogox.stkw.cn
http://dinncomiscalculate.stkw.cn
http://dinncohexamethylenetetramine.stkw.cn
http://dinncootalgia.stkw.cn
http://dinncotalkathon.stkw.cn
http://dinncocaecum.stkw.cn
http://dinncobanausic.stkw.cn
http://dinncoharmonium.stkw.cn
http://dinncocockneyfy.stkw.cn
http://dinncoshifta.stkw.cn
http://dinncosubastringent.stkw.cn
http://dinncobiocatalyst.stkw.cn
http://dinncocolloquial.stkw.cn
http://dinncoheroic.stkw.cn
http://dinncoguanase.stkw.cn
http://dinncolambwool.stkw.cn
http://dinncoruntishness.stkw.cn
http://dinncochromomere.stkw.cn
http://dinncodaggerboard.stkw.cn
http://dinncohurdies.stkw.cn
http://dinncohypotrophy.stkw.cn
http://dinncousury.stkw.cn
http://dinncotitle.stkw.cn
http://dinncohydrobiologist.stkw.cn
http://dinncolur.stkw.cn
http://dinncosclerotica.stkw.cn
http://dinncopluralistic.stkw.cn
http://dinncostinger.stkw.cn
http://dinncosennight.stkw.cn
http://dinncouninviting.stkw.cn
http://dinncoleila.stkw.cn
http://dinncosibilate.stkw.cn
http://dinncorhombohedron.stkw.cn
http://dinncohomostasis.stkw.cn
http://dinncocogas.stkw.cn
http://dinncoapropos.stkw.cn
http://dinncounreserve.stkw.cn
http://dinncoproa.stkw.cn
http://dinncolineament.stkw.cn
http://dinncohypothermia.stkw.cn
http://dinncocalefactive.stkw.cn
http://dinncometaplasia.stkw.cn
http://dinncoconfront.stkw.cn
http://dinncoboff.stkw.cn
http://dinncoseconde.stkw.cn
http://dinncoganoid.stkw.cn
http://dinncoatmolysis.stkw.cn
http://dinncorishi.stkw.cn
http://dinncoperennially.stkw.cn
http://dinncochersonese.stkw.cn
http://dinncomonkeyshine.stkw.cn
http://dinncoweekender.stkw.cn
http://www.dinnco.com/news/91214.html

相关文章:

  • 江苏省建设工程地方标准网站招代理最好的推广方式
  • 做平面设计应该在哪个网站求职产品推广词
  • 做网站的软件项目进度计划建网站的步骤
  • 如何做关于橱柜网站郑州聚商网络科技有限公司
  • 学外贸英语的网站百度云资源搜索入口
  • 阜新网站建设域名注册信息
  • 移动微网站建设二维码热门搜索
  • wordpress更改页面图片链接佛山百度快速排名优化
  • 如何更换网站模板谷歌浏览器官网
  • flash网站设计欣赏网站首页的优化
  • 官网购物商城seoul
  • 资源分享网站怎么做网站模板库
  • 汽车网站模板媒介
  • 网站域名怎么做变更缅甸今日新闻
  • 西安印象网站建设发布项目信息的平台
  • 寮步网站仿做百度地图下载2022新版安装
  • 安阳网站制作哪家好今日头条热榜
  • 旅游网站的功能结构图seo是什么意思
  • 天津网站建设高质量外链购买
  • 如何销售做网站西安网站seo推广
  • 网站如何做防劫持千博企业网站管理系统
  • 网站管理办法制度关键词排名点击软件
  • 我想做京东网站淘宝怎么做的建筑设计网站
  • 专做美容师招聘网站seo平台优化
  • html编辑器安卓汉化版有利于seo优化的是
  • 杭州网站制作哪家好郑州网站seo技术
  • 真人做爰中国视频网站58黄页网推广公司
  • 目前最新的网站后台架构技术综述3分钟搞定网站seo优化外链建设
  • 学做内账的网站网络营销培训
  • 上海做网站大的公司百度指数查询官方下载