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

河北省建设厅网站首页用什么软件做网站最好

河北省建设厅网站首页,用什么软件做网站最好,大同哪有做网站的,游戏开发制作培训前言 本文章是本人在开发过程中&#xff0c;遇到使用树形数据&#xff0c;动态单选或多选的需求&#xff0c;element中没有这种组件&#xff0c;故自己封装一个&#xff0c;欢迎多多指教 开发环境&#xff1a;element-UI、vue2 组件效果 单选 多选 组件引用 <treeselec…

前言

本文章是本人在开发过程中,遇到使用树形数据,动态单选或多选的需求,element中没有这种组件,故自己封装一个,欢迎多多指教

开发环境:element-UI、vue2

组件效果

单选

多选

组件引用

<treeselect v-model="form.parentId":options="deptOptions":props="{value:'id',label:'name',children: 'children'}":placeholder="'选择上级部门'"/>

组件代码

<template><div><el-selectref="treeSelect"popper-class="custom-select-popper"style="width: 100%"v-model="valueLabel":clearable="clearable":placeholder="placeholder":multiple="multiple"@clear="handleClear"@remove-tag="handleRemoveTag"><el-input v-if="filter"v-model="filterText":placeholder="filterPlaceholder" style="margin-top: -6px;"/><el-option :value="value" :label="option.name" class="select-options"><el-treeid="tree-option"ref="treeSelectTree":accordion="accordion":data="options":props="props":node-key="props.value":highlight-current="!multiple":show-checkbox="multiple":check-strictly="checkStrictly":default-expand-all="expandAll":expand-on-click-node="multiple":filter-node-method="filterNode"@node-click="handleNodeClick"@check="handleNodeCheckbox"><span slot-scope="{ node, data }" class="tree_label">{{ node.label }}</span></el-tree></el-option></el-select></div>
</template>
<script>
export default {name: 'TreeSelect',model: {prop: 'value',event: 'change'},props: {value: {type: [String, Number, Object, Array],default: () => {return ''}},clearable: {type: Boolean,default: true},placeholder: {type: String,default: '请选择'},multipleLimit: {type: Number,default: 2},//--------- filter props -----filter: {type: Boolean,default: true},filterPlaceholder: {type: String,default: '请输入关键字'},//----- tree props -----accordion: {type: Boolean,default: false},options: {type: Array,default: () => {return []}},props: {type: Object,default: () => {return {value: 'id',label: 'label',children: 'children'}}},expandAll: {type: Boolean,default: false},checkStrictly: {type: Boolean,default: false}},data() {return {tp: {value: 'id',label: 'label',children: 'children',prentId: 'parentId'},multiple: false,valueLabel: [],option: {id: '',name: ''},filterText: undefined,valueId: [],treeIds: []}},watch: {valueId() {if (this.multiple) {let valueStr = ''if (this.value instanceof Array) {valueStr = this.value.join()} else {valueStr = '' + this.value}if (valueStr !== this.valueId.join()) {this.$emit('change', this.valueId)}} else {let id = this.valueId.length > 0 ? this.valueId[0] : undefinedif (id !== this.value) {this.$emit('change', id)}}},value: {handler(newVal, oldVal) {if (newVal !== oldVal) {this.init()}}},filterText: {handler(newVal, oldVal) {if (newVal !== oldVal) {this.$refs.treeSelectTree.filter(newVal)}}}},mounted() {for (let key in this.tp) {if (this.props[key] !== undefined) {this.tp[key] = this.props[key]}}this.multiple = this.multipleLimit > 1this.init()this.$nextTick(() => {if (this.multiple) {document.getElementsByClassName('el-select__tags')[0].style.maxHeight = document.getElementsByClassName('el-select')[0].offsetHeight * 2 - 4 + 'px'}})},methods: {init() {if (this.value instanceof Array) {this.valueId = this.value} else if (this.value === undefined) {this.valueId = []} else {this.valueId = [this.value]}if (this.multiple) {for (let id of this.valueId) {this.$refs.treeSelectTree.setChecked(id, true, false)}} else {this.$refs.treeSelectTree.setCurrentKey(this.valueId.length > 0 ? this.valueId[0] : undefined)}this.initValueLabel()this.initTreeIds()this.initScroll()},// 初始化滚动条initScroll() {this.$nextTick(() => {let scrollWrap = document.querySelectorAll('.el-scrollbar .el-select-dropdown__wrap')[0]scrollWrap.style.cssText = 'margin: 0px; max-height: none; overflow: hidden;'let scrollBar = document.querySelectorAll('.el-scrollbar .el-scrollbar__bar')scrollBar.forEach((ele) => (ele.style.width = 0))})},initTreeIds() {let treeIds = []let _this = thisfunction traverse(nodes) {for (let node of nodes) {treeIds.push(node[_this.tp.value])if (node[_this.tp.children]) {traverse(node[_this.tp.children])}}}traverse(this.options)this.treeIds = treeIds},initValueLabel() {let labels = []let _this = thisfor (let id of this.valueId) {let node = this.traverse(this.options, node => node[_this.tp.value] === id)if (node) {labels.push(node[_this.tp.label])}}if (this.multiple) {this.valueLabel = labelsthis.option.name = labels.join()} else {this.valueLabel = labels.length > 0 ? labels[0] : undefinedthis.option.name = this.valueLabel}},traverse(tree, func) {for (let node of tree) {if (func(node)) {return node}if (node[this.tp.children]) {let result = this.traverse(node[this.tp.children], func)if (result !== undefined) {return result}}}return undefined},handleClear() {this.valueLabel = []this.valueId = []if (this.multiple) {for (let id of this.treeIds) {this.$refs.treeSelectTree.setChecked(id, false, false)}} else {this.$refs.treeSelectTree.setCurrentKey(null)}},/* 树filter方法 */filterNode(value, data) {if (!value) return truereturn data[this.props.label].indexOf(value) !== -1},/* 树节点点击事件 */handleNodeClick(data, node) {if (!this.multiple) {this.filterText = ''this.valueId = [data[this.tp.value]]}if(node.childNodes){node.expanded = true}},handleNodeCheckbox(data, node) {if (this.multiple) {if (this.multipleLimit >= node.checkedKeys.length) {this.valueId = node.checkedKeys} else {this.$refs.treeSelectTree.setChecked(data, false, !this.checkStrictly)this.$message.error('最多选择' + this.multipleLimit + '项')}}},handleRemoveTag(tag) {let n = this.traverse(this.options, node => node[this.tp.label] === tag)if (n) {this.$refs.treeSelectTree.setChecked(n[this.tp.value], false, !this.checkStrictly)}this.valueId = this.$refs.treeSelectTree.getCheckedKeys()}}
}</script><style scoped lang="scss">
::v-deep .el-select__tags {overflow: auto;
}
.custom-select-popper{}.el-scrollbar {.el-scrollbar__view {.el-select-dropdown__item {height: auto;max-height: 300px;padding: 0;overflow: hidden;overflow-y: auto;}.el-select-dropdown__item.selected {font-weight: normal;}}
}ul li {.el-tree {.el-tree-node__content {height: auto;padding: 0 20px;}.el-tree-node__label {font-weight: normal;}.is-current > .el-tree-node__label{color: #409eff;font-weight: 700;}}
}.tree_label {line-height: 23px;.label_index {background-color: rgb(0, 175, 255);width: 22px;height: 22px;display: inline-flex;border-radius: 4px;.label_index_font {color: #ffffff;width: 100%;text-align: center;}}
}
</style>
http://www.yayakq.cn/news/871658/

相关文章:

  • 什么网站的易用性专业佛山网站建设
  • 制作网站注册页面做健康食品的网站
  • 网站建设方案编写人拍摄形象宣传片
  • 网站建设搜索优化网站的设计与实现
  • 深圳手机商城网站设计多少钱兰州网站制作怎么样
  • 建一个产品介绍网站网站建设公司简介模板
  • 团购网站大全做相册网站网站建设策划书
  • 永顺县建设局网站中国建设网 中国建设网
  • 网站网站做任务佣金违法linux做网站方便吗
  • 开发一个网站需要的技术深圳工业设计展2022
  • 网站优化 ppt布谷海南网站建设
  • 一个网站需要多长时间企业网站建设方案及报价
  • 繁体网站怎么做管理系统入口admin
  • 网站建设策划内容网站建设与管理方案书
  • 网站建设开票税率网站建设方
  • 成都哪家做网站建设比较好做网站架构需要什么工具
  • 网站建设网站制作有限产品详情页模板免费
  • thinkphpcmf网站开发wordpress 爱
  • 开发商城网站多少钱手机版网站优化
  • 手机端网站首页怎么做做移动端网站
  • html5做图书馆网站股票推荐怎么做网站
  • 上海网站建设哪家做得好wordpress采集图片不显示
  • 网页建立网站平台房山建设网站
  • 中铁建设门户网站营销型网站制作步骤五个
  • 顺义手机网站建设iis wordpress伪静态
  • 长春旅游网站开发深圳网站建设工作
  • 做网站dreamwa动易网站无法安装
  • 营销型网站建设大概多少钱网站服务器租用报价
  • 做网站做百姓网站外推广怎么做
  • 做最好最全的命理网站网站建设是否需形成无形资产