提交 20c05fcc 作者: wk

组织切换组织树优化替换

父级 6199a14c
...@@ -3,16 +3,16 @@ const $config = { ...@@ -3,16 +3,16 @@ const $config = {
loginTemplateNo: "industry-0001", loginTemplateNo: "industry-0001",
systemCode: "buildingSite", systemCode: "buildingSite",
/* 授权码 */ /* 授权码 */
// authCode: "477A0661-EF04-11F7-9D69-0BDD73F06500", authCode: "477A0661-EF04-11F7-9D69-0BDD73F06500",
// authCode: "07EC0FDA-0249-6DB3-7422-0AFFF34E0E90", //测试 // authCode: "07EC0FDA-0249-6DB3-7422-0AFFF34E0E90", //测试
authCode: "D0539533-E169-5338-8ED7-3FAD554F4F62", //正式 // authCode: "D0539533-E169-5338-8ED7-3FAD554F4F62", //正式
pageSize: 20, pageSize: 20,
isPage: 1, isPage: 1,
smsCfg: "industry", smsCfg: "industry",
/* api域名 */ /* api域名 */
// base: "https://dev-console-api.hzdingmao.com", base: "https://dev-console-api.hzdingmao.com",
// base: "https://test-console-api.hzdingmao.com", // base: "https://test-console-api.hzdingmao.com",
base: "https://console-api.hibuilding.cn", // base: "https://console-api.hibuilding.cn",
/* 工地沟通日 */ /* 工地沟通日 */
// gtrBase:"https://cwcd-h5.huizhucloud.com",//测试 // gtrBase:"https://cwcd-h5.huizhucloud.com",//测试
gtrBase: "https://gdt-front-mobile.hibuilding.cn", //生产 gtrBase: "https://gdt-front-mobile.hibuilding.cn", //生产
......
...@@ -321,8 +321,8 @@ ...@@ -321,8 +321,8 @@
} }
.ly-tree-node__icon { .ly-tree-node__icon {
width: 30rpx; width: 40rpx;
height: 30rpx; height: 40rpx;
overflow: hidden; overflow: hidden;
margin-right: 16rpx; margin-right: 16rpx;
} }
...@@ -334,8 +334,8 @@ ...@@ -334,8 +334,8 @@
} }
.ly-tree-node__label { .ly-tree-node__label {
font-size: 32rpx; font-size: 28rpx;
color: #333333; color: #606266;
width: 750rpx; width: 750rpx;
} }
......
...@@ -5,16 +5,26 @@ ...@@ -5,16 +5,26 @@
<view class="ly-loader-inner">加载中...</view> <view class="ly-loader-inner">加载中...</view>
</view> </view>
</template> </template>
<template v-else> <template v-else>
<view v-if="isEmpty || !visible" class="ly-empty"> <view v-if="isEmpty || !visible"
class="ly-empty">
{{emptyText}} {{emptyText}}
</view> </view>
<view :key="updateKey" class="ly-tree" :class="{'is-empty': isEmpty || !visible}" role="tree" <view :key="updateKey"
class="ly-tree"
:class="{'is-empty': isEmpty || !visible}"
role="tree"
name="LyTreeExpand"> name="LyTreeExpand">
<ly-tree-node v-for="nodeId in childNodesId" :nodeId="nodeId" :render-after-expand="renderAfterExpand" <ly-tree-node v-for="nodeId in childNodesId"
:show-checkbox="showCheckbox" :show-radio="showRadio" :check-only-leaf="checkOnlyLeaf" :nodeId="nodeId"
:key="getNodeKey(nodeId)" :indent="indent" :icon-class="iconClass"> :render-after-expand="renderAfterExpand"
:show-checkbox="showCheckbox"
:show-radio="showRadio"
:check-only-leaf="checkOnlyLeaf"
:key="getNodeKey(nodeId)"
:indent="indent"
:icon-class="iconClass">
</ly-tree-node> </ly-tree-node>
</view> </view>
</template> </template>
...@@ -24,20 +34,18 @@ ...@@ -24,20 +34,18 @@
<script> <script>
import Vue from 'vue' import Vue from 'vue'
import TreeStore from './model/tree-store.js'; import TreeStore from './model/tree-store.js';
import { import {getNodeKey} from './tool/util.js';
getNodeKey
} from './tool/util.js';
import LyTreeNode from './ly-tree-node.vue'; import LyTreeNode from './ly-tree-node.vue';
export default { export default {
name: 'LyTree', name: 'LyTree',
componentName: 'LyTree', componentName: 'LyTree',
components: { components: {
LyTreeNode LyTreeNode
}, },
data() { data() {
return { return {
updateKey: new Date().getTime(), // 数据更新的时候,重新渲染树 updateKey: new Date().getTime(), // 数据更新的时候,重新渲染树
...@@ -50,102 +58,102 @@ ...@@ -50,102 +58,102 @@
childNodesId: [] childNodesId: []
}; };
}, },
provide() { provide() {
return { return {
tree: this tree: this
} }
}, },
props: { props: {
// 展示数据 // 展示数据
treeData: Array, treeData: Array,
// 自主控制loading加载,避免数据还没获取到的空档出现“暂无数据”字样 // 自主控制loading加载,避免数据还没获取到的空档出现“暂无数据”字样
ready: { ready: {
type: Boolean, type: Boolean,
default: true default: true
}, },
// 内容为空的时候展示的文本 // 内容为空的时候展示的文本
emptyText: { emptyText: {
type: String, type: String,
default: '暂无数据' default: '暂无数据'
}, },
// 是否在第一次展开某个树节点后才渲染其子节点 // 是否在第一次展开某个树节点后才渲染其子节点
renderAfterExpand: { renderAfterExpand: {
type: Boolean, type: Boolean,
default: true default: true
}, },
// 每个树节点用来作为唯一标识的属性,整棵树应该是唯一的 // 每个树节点用来作为唯一标识的属性,整棵树应该是唯一的
nodeKey: String, nodeKey: String,
// 在显示复选框的情况下,是否严格的遵循父子不互相关联的做法,默认为 false // 在显示复选框的情况下,是否严格的遵循父子不互相关联的做法,默认为 false
checkStrictly: Boolean, checkStrictly: Boolean,
// 是否默认展开所有节点 // 是否默认展开所有节点
defaultExpandAll: Boolean, defaultExpandAll: Boolean,
// 切换全部展开、全部折叠 // 切换全部展开、全部折叠
toggleExpendAll: Boolean, toggleExpendAll: Boolean,
// 是否在点击节点的时候展开或者收缩节点, 默认值为 true,如果为 false,则只有点箭头图标的时候才会展开或者收缩节点 // 是否在点击节点的时候展开或者收缩节点, 默认值为 true,如果为 false,则只有点箭头图标的时候才会展开或者收缩节点
expandOnClickNode: { expandOnClickNode: {
type: Boolean, type: Boolean,
default: true default: true
}, },
// 选中的时候展开节点 // 选中的时候展开节点
expandOnCheckNode: { expandOnCheckNode: {
type: Boolean, type: Boolean,
default: true default: true
}, },
// 是否在点击节点的时候选中节点,默认值为 false,即只有在点击复选框时才会选中节点 // 是否在点击节点的时候选中节点,默认值为 false,即只有在点击复选框时才会选中节点
checkOnClickNode: Boolean, checkOnClickNode: Boolean,
checkDescendants: { checkDescendants: {
type: Boolean, type: Boolean,
default: false default: false
}, },
// 展开子节点的时候是否自动展开父节点 // 展开子节点的时候是否自动展开父节点
autoExpandParent: { autoExpandParent: {
type: Boolean, type: Boolean,
default: true default: true
}, },
// 默认勾选的节点的 key 的数组 // 默认勾选的节点的 key 的数组
defaultCheckedKeys: Array, defaultCheckedKeys: Array,
// 默认展开的节点的 key 的数组 // 默认展开的节点的 key 的数组
defaultExpandedKeys: Array, defaultExpandedKeys: Array,
// 是否展开当前节点的父节点 // 是否展开当前节点的父节点
expandCurrentNodeParent: Boolean, expandCurrentNodeParent: Boolean,
// 当前选中的节点 // 当前选中的节点
currentNodeKey: [String, Number], currentNodeKey: [String, Number],
// 是否最后一层叶子节点才显示单选/多选框 // 是否最后一层叶子节点才显示单选/多选框
checkOnlyLeaf: { checkOnlyLeaf: {
type: Boolean, type: Boolean,
default: false default: false
}, },
// 节点是否可被选择 // 节点是否可被选择
showCheckbox: { showCheckbox: {
type: Boolean, type: Boolean,
default: false default: false
}, },
// 节点单选 // 节点单选
showRadio: { showRadio: {
type: Boolean, type: Boolean,
default: false default: false
}, },
// 配置选项 // 配置选项
props: { props: {
type: [Object, Function], type: [Object, Function],
...@@ -157,76 +165,74 @@ ...@@ -157,76 +165,74 @@
}; };
} }
}, },
// 是否懒加载子节点,需与 load 方法结合使用 // 是否懒加载子节点,需与 load 方法结合使用
lazy: { lazy: {
type: Boolean, type: Boolean,
default: false default: false
}, },
// 是否高亮当前选中节点,默认值是 false // 是否高亮当前选中节点,默认值是 false
highlightCurrent: Boolean, highlightCurrent: Boolean,
// 加载子树数据的方法,仅当 lazy 属性为true 时生效 // 加载子树数据的方法,仅当 lazy 属性为true 时生效
load: Function, load: Function,
// 对树节点进行筛选时执行的方法,返回 true 表示这个节点可以显示,返回 false 则表示这个节点会被隐藏 // 对树节点进行筛选时执行的方法,返回 true 表示这个节点可以显示,返回 false 则表示这个节点会被隐藏
filterNodeMethod: Function, filterNodeMethod: Function,
// 搜索时是否展示匹配项的所有子节点 // 搜索时是否展示匹配项的所有子节点
childVisibleForFilterNode: { childVisibleForFilterNode: {
type: Boolean, type: Boolean,
default: false default: false
}, },
// 是否每次只打开一个同级树节点展开 // 是否每次只打开一个同级树节点展开
accordion: Boolean, accordion: Boolean,
// 相邻级节点间的水平缩进,单位为像素 // 相邻级节点间的水平缩进,单位为像素
indent: { indent: {
type: Number, type: Number,
default: 18 default: 18
}, },
// 自定义树节点的展开图标 // 自定义树节点的展开图标
iconClass: String, iconClass: String,
// 是否显示节点图标,如果配置为true,需要配置props中对应的图标属性名称 // 是否显示节点图标,如果配置为true,需要配置props中对应的图标属性名称
showNodeIcon: { showNodeIcon: {
type: Boolean, type: Boolean,
default: false default: false
}, },
// 当节点图标显示出错时,显示的默认图标 // 当节点图标显示出错时,显示的默认图标
defaultNodeIcon: { defaultNodeIcon: {
type: String, type: String,
default: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/doc/github.svg' default: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/doc/github.svg'
}, },
// 如果数据量较大,建议不要在node节点中添加parent属性,会造成性能损耗 // 如果数据量较大,建议不要在node节点中添加parent属性,会造成性能损耗
isInjectParentInNode: { isInjectParentInNode: {
type: Boolean, type: Boolean,
default: false default: false
} }
}, },
computed: { computed: {
isEmpty() { isEmpty() {
if (this.store.root) { if (this.store.root) {
const childNodes = this.store.root.getChildNodes(this.childNodesId); const childNodes = this.store.root.getChildNodes(this.childNodesId);
return !childNodes || childNodes.length === 0 || childNodes.every(({ return !childNodes || childNodes.length === 0 || childNodes.every(({visible}) => !visible);
visible
}) => !visible);
} }
return true; return true;
}, },
showLoading() { showLoading() {
return !(this.store.ready && this.ready); return !(this.store.ready && this.ready);
} }
}, },
watch: { watch: {
toggleExpendAll(newVal) { toggleExpendAll(newVal) {
this.store.toggleExpendAll(newVal); this.store.toggleExpendAll(newVal);
...@@ -247,7 +253,7 @@ ...@@ -247,7 +253,7 @@
'store.root.visible'(newVal) { 'store.root.visible'(newVal) {
this.visible = newVal; this.visible = newVal;
}, },
childNodesId() { childNodesId(){
this.$nextTick(() => { this.$nextTick(() => {
this.$emit('ly-tree-render-completed'); this.$emit('ly-tree-render-completed');
}); });
...@@ -260,233 +266,232 @@ ...@@ -260,233 +266,232 @@
deep: true deep: true
} }
}, },
methods: { methods: {
/* /*
* @description 对树节点进行筛选操作 * @description 对树节点进行筛选操作
* @method filter * @method filter
* @param {all} value 在 filter-node-method 中作为第一个参数 * @param {all} value 在 filter-node-method 中作为第一个参数
* @param {Object} data 搜索指定节点的节点数据,不传代表搜索所有节点,假如要搜索A节点下面的数据,那么nodeData代表treeData中A节点的数据 * @param {Object} data 搜索指定节点的节点数据,不传代表搜索所有节点,假如要搜索A节点下面的数据,那么nodeData代表treeData中A节点的数据
*/ */
filter(value, data) { filter(value, data) {
if (!this.filterNodeMethod) throw new Error('[Tree] filterNodeMethod is required when filter'); if (!this.filterNodeMethod) throw new Error('[Tree] filterNodeMethod is required when filter');
this.store.filter(value, data); this.store.filter(value, data);
}, },
/* /*
* @description 获取节点的唯一标识符 * @description 获取节点的唯一标识符
* @method getNodeKey * @method getNodeKey
* @param {String, Number} nodeId * @param {String, Number} nodeId
* @return {String, Number} 匹配到的数据中的某一项数据 * @return {String, Number} 匹配到的数据中的某一项数据
*/ */
getNodeKey(nodeId) { getNodeKey(nodeId) {
let node = this.store.root.getChildNodes([nodeId])[0]; let node = this.store.root.getChildNodes([nodeId])[0];
return getNodeKey(this.nodeKey, node.data); return getNodeKey(this.nodeKey, node.data);
}, },
/* /*
* @description 获取节点路径 * @description 获取节点路径
* @method getNodePath * @method getNodePath
* @param {Object} data 节点数据 * @param {Object} data 节点数据
* @return {Array} 路径数组 * @return {Array} 路径数组
*/ */
getNodePath(data) { getNodePath(data) {
return this.store.getNodePath(data); return this.store.getNodePath(data);
}, },
/* /*
* @description 若节点可被选择(即 show-checkbox 为 true),则返回目前被选中的节点所组成的数组 * @description 若节点可被选择(即 show-checkbox 为 true),则返回目前被选中的节点所组成的数组
* @method getCheckedNodes * @method getCheckedNodes
* @param {Boolean} leafOnly 是否只是叶子节点,默认false * @param {Boolean} leafOnly 是否只是叶子节点,默认false
* @param {Boolean} includeHalfChecked 是否包含半选节点,默认false * @param {Boolean} includeHalfChecked 是否包含半选节点,默认false
* @return {Array} 目前被选中的节点所组成的数组 * @return {Array} 目前被选中的节点所组成的数组
*/ */
getCheckedNodes(leafOnly, includeHalfChecked) { getCheckedNodes(leafOnly, includeHalfChecked) {
return this.store.getCheckedNodes(leafOnly, includeHalfChecked); return this.store.getCheckedNodes(leafOnly, includeHalfChecked);
}, },
/* /*
* @description 若节点可被选择(即 show-checkbox 为 true),则返回目前被选中的节点的 key 所组成的数组 * @description 若节点可被选择(即 show-checkbox 为 true),则返回目前被选中的节点的 key 所组成的数组
* @method getCheckedKeys * @method getCheckedKeys
* @param {Boolean} leafOnly 是否只是叶子节点,默认false,若为 true 则仅返回被选中的叶子节点的 keys * @param {Boolean} leafOnly 是否只是叶子节点,默认false,若为 true 则仅返回被选中的叶子节点的 keys
* @param {Boolean} includeHalfChecked 是否返回indeterminate为true的节点,默认false * @param {Boolean} includeHalfChecked 是否返回indeterminate为true的节点,默认false
* @return {Array} 目前被选中的节点所组成的数组 * @return {Array} 目前被选中的节点所组成的数组
*/ */
getCheckedKeys(leafOnly, includeHalfChecked) { getCheckedKeys(leafOnly, includeHalfChecked) {
return this.store.getCheckedKeys(leafOnly, includeHalfChecked); return this.store.getCheckedKeys(leafOnly, includeHalfChecked);
}, },
/* /*
* @description 获取当前被选中节点的 data,若没有节点被选中则返回 null * @description 获取当前被选中节点的 data,若没有节点被选中则返回 null
* @method getCurrentNode * @method getCurrentNode
* @return {Object} 当前被选中节点的 data,若没有节点被选中则返回 null * @return {Object} 当前被选中节点的 data,若没有节点被选中则返回 null
*/ */
getCurrentNode() { getCurrentNode() {
const currentNode = this.store.getCurrentNode(); const currentNode = this.store.getCurrentNode();
return currentNode ? currentNode.data : null; return currentNode ? currentNode.data : null;
}, },
/* /*
* @description 获取当前被选中节点的 key,若没有节点被选中则返回 null * @description 获取当前被选中节点的 key,若没有节点被选中则返回 null
* @method getCurrentKey * @method getCurrentKey
* @return {all} 当前被选中节点的 key, 若没有节点被选中则返回 null * @return {all} 当前被选中节点的 key, 若没有节点被选中则返回 null
*/ */
getCurrentKey() { getCurrentKey() {
const currentNode = this.getCurrentNode(); const currentNode = this.getCurrentNode();
return currentNode ? currentNode[this.nodeKey] : null; return currentNode ? currentNode[this.nodeKey] : null;
}, },
/* /*
* @description 设置全选/取消全选 * @description 设置全选/取消全选
* @method setCheckAll * @method setCheckAll
* @param {Boolean} isCheckAll 选中状态,默认为true * @param {Boolean} isCheckAll 选中状态,默认为true
*/ */
setCheckAll(isCheckAll = true) { setCheckAll(isCheckAll = true) {
if (this.showRadio) throw new Error('You set the "show-radio" property, so you cannot select all nodes'); if (this.showRadio) throw new Error('You set the "show-radio" property, so you cannot select all nodes');
if (!this.showCheckbox) console.warn( if (!this.showCheckbox) console.warn('You have not set the property "show-checkbox". Please check your settings');
'You have not set the property "show-checkbox". Please check your settings');
this.store.setCheckAll(isCheckAll); this.store.setCheckAll(isCheckAll);
}, },
/* /*
* @description 设置目前勾选的节点 * @description 设置目前勾选的节点
* @method setCheckedNodes * @method setCheckedNodes
* @param {Array} nodes 接收勾选节点数据的数组 * @param {Array} nodes 接收勾选节点数据的数组
* @param {Boolean} leafOnly 是否只是叶子节点, 若为 true 则仅设置叶子节点的选中状态,默认值为 false * @param {Boolean} leafOnly 是否只是叶子节点, 若为 true 则仅设置叶子节点的选中状态,默认值为 false
*/ */
setCheckedNodes(nodes, leafOnly) { setCheckedNodes(nodes, leafOnly) {
this.store.setCheckedNodes(nodes, leafOnly); this.store.setCheckedNodes(nodes, leafOnly);
}, },
/* /*
* @description 通过 keys 设置目前勾选的节点 * @description 通过 keys 设置目前勾选的节点
* @method setCheckedKeys * @method setCheckedKeys
* @param {Array} keys 勾选节点的 key 的数组 * @param {Array} keys 勾选节点的 key 的数组
* @param {Boolean} leafOnly 是否只是叶子节点, 若为 true 则仅设置叶子节点的选中状态,默认值为 false * @param {Boolean} leafOnly 是否只是叶子节点, 若为 true 则仅设置叶子节点的选中状态,默认值为 false
*/ */
setCheckedKeys(keys, leafOnly) { setCheckedKeys(keys, leafOnly) {
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedKeys'); if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedKeys');
this.store.setCheckedKeys(keys, leafOnly); this.store.setCheckedKeys(keys, leafOnly);
}, },
/* /*
* @description 通过 key / data 设置某个节点的勾选状态 * @description 通过 key / data 设置某个节点的勾选状态
* @method setChecked * @method setChecked
* @param {all} data 勾选节点的 key 或者 data * @param {all} data 勾选节点的 key 或者 data
* @param {Boolean} checked 节点是否选中 * @param {Boolean} checked 节点是否选中
* @param {Boolean} deep 是否设置子节点 ,默认为 false * @param {Boolean} deep 是否设置子节点 ,默认为 false
*/ */
setChecked(data, checked, deep) { setChecked(data, checked, deep) {
this.store.setChecked(data, checked, deep); this.store.setChecked(data, checked, deep);
}, },
/* /*
* @description 若节点可被选择(即 show-checkbox 为 true),则返回目前半选中的节点所组成的数组 * @description 若节点可被选择(即 show-checkbox 为 true),则返回目前半选中的节点所组成的数组
* @method getHalfCheckedNodes * @method getHalfCheckedNodes
* @return {Array} 目前半选中的节点所组成的数组 * @return {Array} 目前半选中的节点所组成的数组
*/ */
getHalfCheckedNodes() { getHalfCheckedNodes() {
return this.store.getHalfCheckedNodes(); return this.store.getHalfCheckedNodes();
}, },
/* /*
* @description 若节点可被选择(即 show-checkbox 为 true),则返回目前半选中的节点的 key 所组成的数组 * @description 若节点可被选择(即 show-checkbox 为 true),则返回目前半选中的节点的 key 所组成的数组
* @method getHalfCheckedKeys * @method getHalfCheckedKeys
* @return {Array} 目前半选中的节点的 key 所组成的数组 * @return {Array} 目前半选中的节点的 key 所组成的数组
*/ */
getHalfCheckedKeys() { getHalfCheckedKeys() {
return this.store.getHalfCheckedKeys(); return this.store.getHalfCheckedKeys();
}, },
/* /*
* @description 通过 node 设置某个节点的当前选中状态 * @description 通过 node 设置某个节点的当前选中状态
* @method setCurrentNode * @method setCurrentNode
* @param {Object} node 待被选节点的 node * @param {Object} node 待被选节点的 node
*/ */
setCurrentNode(node) { setCurrentNode(node) {
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentNode'); if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentNode');
this.store.setUserCurrentNode(node); this.store.setUserCurrentNode(node);
}, },
/* /*
* @description 通过 key 设置某个节点的当前选中状态 * @description 通过 key 设置某个节点的当前选中状态
* @method setCurrentKey * @method setCurrentKey
* @param {all} key 待被选节点的 key,若为 null 则取消当前高亮的节点 * @param {all} key 待被选节点的 key,若为 null 则取消当前高亮的节点
*/ */
setCurrentKey(key) { setCurrentKey(key) {
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentKey'); if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentKey');
this.store.setCurrentNodeKey(key); this.store.setCurrentNodeKey(key);
}, },
/* /*
* @description 根据 data 或者 key 拿到 Tree 组件中的 node * @description 根据 data 或者 key 拿到 Tree 组件中的 node
* @method getNode * @method getNode
* @param {all} data 要获得 node 的 key 或者 data * @param {all} data 要获得 node 的 key 或者 data
*/ */
getNode(data) { getNode(data) {
return this.store.getNode(data); return this.store.getNode(data);
}, },
/* /*
* @description 删除 Tree 中的一个节点 * @description 删除 Tree 中的一个节点
* @method remove * @method remove
* @param {all} data 要删除的节点的 data 或者 node * @param {all} data 要删除的节点的 data 或者 node
*/ */
remove(data) { remove(data) {
this.store.remove(data); this.store.remove(data);
}, },
/* /*
* @description 为 Tree 中的一个节点追加一个子节点 * @description 为 Tree 中的一个节点追加一个子节点
* @method append * @method append
* @param {Object} data 要追加的子节点的 data * @param {Object} data 要追加的子节点的 data
* @param {Object} parentNode 子节点的 parent 的 data、key 或者 node * @param {Object} parentNode 子节点的 parent 的 data、key 或者 node
*/ */
append(data, parentNode) { append(data, parentNode) {
this.store.append(data, parentNode); this.store.append(data, parentNode);
}, },
/* /*
* @description 为 Tree 的一个节点的前面增加一个节点 * @description 为 Tree 的一个节点的前面增加一个节点
* @method insertBefore * @method insertBefore
* @param {Object} data 要增加的节点的 data * @param {Object} data 要增加的节点的 data
* @param {all} refNode 要增加的节点的后一个节点的 data、key 或者 node * @param {all} refNode 要增加的节点的后一个节点的 data、key 或者 node
*/ */
insertBefore(data, refNode) { insertBefore(data, refNode) {
this.store.insertBefore(data, refNode); this.store.insertBefore(data, refNode);
}, },
/* /*
* @description 为 Tree 的一个节点的后面增加一个节点 * @description 为 Tree 的一个节点的后面增加一个节点
* @method insertAfter * @method insertAfter
* @param {Object} data 要增加的节点的 data * @param {Object} data 要增加的节点的 data
* @param {all} refNode 要增加的节点的前一个节点的 data、key 或者 node * @param {all} refNode 要增加的节点的前一个节点的 data、key 或者 node
*/ */
insertAfter(data, refNode) { insertAfter(data, refNode) {
this.store.insertAfter(data, refNode); this.store.insertAfter(data, refNode);
}, },
/* /*
* @description 通过 keys 设置节点子元素 * @description 通过 keys 设置节点子元素
* @method updateKeyChildren * @method updateKeyChildren
* @param {String, Number} key 节点 key * @param {String, Number} key 节点 key
* @param {Object} data 节点数据的数组 * @param {Object} data 节点数据的数组
*/ */
updateKeyChildren(key, data) { updateKeyChildren(key, data) {
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in updateKeyChild'); if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in updateKeyChild');
this.store.updateChildren(key, data); this.store.updateChildren(key, data);
} }
}, },
created() { created() {
this.isTree = true; this.isTree = true;
let props = this.props; let props = this.props;
if (typeof this.props === 'function') props = this.props(); if (typeof this.props === 'function') props = this.props();
if (typeof props !== 'object') throw new Error('props must be of object type.'); if (typeof props !== 'object') throw new Error('props must be of object type.');
this.store = new TreeStore({ this.store = new TreeStore({
key: this.nodeKey, key: this.nodeKey,
data: this.treeData, data: this.treeData,
...@@ -512,7 +517,7 @@ ...@@ -512,7 +517,7 @@
this.childNodesId = this.store.root.childNodesId; this.childNodesId = this.store.root.childNodesId;
}, },
beforeDestroy() { beforeDestroy() {
if (this.accordion) { if (this.accordion) {
uni.$off(`${this.elId}-tree-node-expand`) uni.$off(`${this.elId}-tree-node-expand`)
...@@ -526,14 +531,14 @@ ...@@ -526,14 +531,14 @@
position: relative; position: relative;
cursor: default; cursor: default;
background: #FFF; background: #FFF;
color: #333333; color: #606266;
padding: 20rpx; padding: 30rpx;
} }
.ly-tree.is-empty { .ly-tree.is-empty {
background: transparent; background: transparent;
} }
/* lyEmpty-start */ /* lyEmpty-start */
.ly-empty { .ly-empty {
width: 100%; width: 100%;
...@@ -541,9 +546,8 @@ ...@@ -541,9 +546,8 @@
justify-content: center; justify-content: center;
margin-top: 100rpx; margin-top: 100rpx;
} }
/* lyEmpty-end */ /* lyEmpty-end */
/* lyLoader-start */ /* lyLoader-start */
.ly-loader { .ly-loader {
margin-top: 100rpx; margin-top: 100rpx;
...@@ -551,7 +555,7 @@ ...@@ -551,7 +555,7 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.ly-loader-inner, .ly-loader-inner,
.ly-loader-inner:before, .ly-loader-inner:before,
.ly-loader-inner:after { .ly-loader-inner:after {
...@@ -560,41 +564,39 @@ ...@@ -560,41 +564,39 @@
width: .5em; width: .5em;
height: 1em; height: 1em;
} }
.ly-loader-inner:before, .ly-loader-inner:before,
.ly-loader-inner:after { .ly-loader-inner:after {
position: absolute; position: absolute;
top: 0; top: 0;
content: ''; content: '';
} }
.ly-loader-inner:before { .ly-loader-inner:before {
left: -1em; left: -1em;
} }
.ly-loader-inner { .ly-loader-inner {
text-indent: -9999em; text-indent: -9999em;
position: relative; position: relative;
font-size: 22rpx; font-size: 22rpx;
animation-delay: 0.16s; animation-delay: 0.16s;
} }
.ly-loader-inner:after { .ly-loader-inner:after {
left: 1em; left: 1em;
animation-delay: 0.32s; animation-delay: 0.32s;
} }
/* lyLoader-end */ /* lyLoader-end */
@keyframes load { @keyframes load {
0%, 0%,
80%, 80%,
100% { 100% {
box-shadow: 0 0 #efefef; box-shadow: 0 0 #efefef;
height: 1em; height: 1em;
} }
40% { 40% {
box-shadow: 0 -1.5em #efefef; box-shadow: 0 -1.5em #efefef;
height: 1.5em; height: 1.5em;
......
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
uni.scanCode({ uni.scanCode({
success(res) { success(res) {
let result = res.result let result = res.result
if (result.indexOf("?") != -1) { if (result.indexOf("?") != -1) { //一物一码
let param = result.split("?")[1] let param = result.split("?")[1]
let params = param.replace(/&/g, '","').replace(/=/g, '":"') let params = param.replace(/&/g, '","').replace(/=/g, '":"')
let paramJson = `{"${params}"}` let paramJson = `{"${params}"}`
...@@ -129,7 +129,8 @@ ...@@ -129,7 +129,8 @@
}) })
} }
} else { } else {
that.$toast.showToast("二维码格式不正确") that.orgCode(res)
// that.$toast.showToast("二维码格式不正确")
} }
}, },
fail() { fail() {
...@@ -137,6 +138,36 @@ ...@@ -137,6 +138,36 @@
} }
}) })
}, },
orgCode(res) {
try {
let result = JSON.parse(res.result)
if (result && typeof result == 'object') {
let type = result.type
if (type == "company") {
this.code = result.text
uni.navigateTo({
url: `/pages/login/joinDepartment/joinDepartment?code=${this.code}&type=company`
})
} else if (type == "project") {
this.code = result.text
uni.navigateTo({
url: `/pages/login/joinDepartment/joinDepartment?code=${this.code}&type=project&projectId=${result.ext.id}`
})
} else if (type == "department") {
this.code = result.text
uni.navigateTo({
url: `/pages/login/joinDepartment/joinDepartment?code=${this.code}&type=department`
})
} else {
this.$toast.showToast("二维码格式不正确")
}
} else {
this.$toast.showToast("二维码格式不正确")
}
} catch (e) {
this.$toast.showToast("二维码格式不正确")
}
}
} }
} }
</script> </script>
......
...@@ -473,7 +473,10 @@ ...@@ -473,7 +473,10 @@
"navigationBarTextStyle": "white", "navigationBarTextStyle": "white",
"navigationBarTitleText": "智慧工地一点通", "navigationBarTitleText": "智慧工地一点通",
"navigationBarBackgroundColor": "#3B73FE", "navigationBarBackgroundColor": "#3B73FE",
"backgroundColor": "#3B73FE" "backgroundColor": "#3B73FE",
"usingComponents": {
"ly-tree-node": "/components/ly-tree/ly-tree-node"
}
}, },
"uniIdRouter": {}, "uniIdRouter": {},
"tabBar": { "tabBar": {
......
...@@ -189,7 +189,7 @@ ...@@ -189,7 +189,7 @@
return return
} }
uni.navigateTo({ uni.navigateTo({
url: "/pages/mine/changeOrg/changeOrg" url: "/pagesSub/mine/changeOrg/changeOrg"
}) })
}, },
toIndex(model) { toIndex(model) {
......
...@@ -568,21 +568,17 @@ ...@@ -568,21 +568,17 @@
//如果是工人 获取工人当前项目 //如果是工人 获取工人当前项目
if (this.role == 'PM') { if (this.role == 'PM') {
if (jobs) { if (jobs) {
let currentJob = jobs[0]
uni.setStorageSync("org_no", currentJob.org_no)
uni.setStorageSync("org_id", currentJob.org_id)
//当前岗位 判断当前岗位是项目部还是其他 //当前岗位 判断当前岗位是项目部还是其他
if (this.userInfo.user.dept_type == '2') { //项目级 if (this.userInfo.user.dept_type == '2') { //项目级
this.project_id = uni.getStorageSync("project_id") uni.setStorageSync("org_name", currentJob.dept_name)
console.log("当前组织", this.project_id);
if (!this.project_id) {
this.loadProject()
} else {
this.initData()
}
} else { } else {
let currentJob = jobs[0]
uni.setStorageSync("org_no", currentJob.org_no)
uni.setStorageSync("org_name", currentJob.org_name) uni.setStorageSync("org_name", currentJob.org_name)
this.initData() this.initData()
} }
this.initData()
} }
} else { } else {
this.project_id = uni.getStorageSync("project_id") this.project_id = uni.getStorageSync("project_id")
......
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
<view class="enter">{{isCurrent(item)?"当前组织":""}}</view> <view class="enter">{{isCurrent(item)?"当前组织":""}}</view>
</view> </view>
<view class="job-content" v-if="item.isOpen"> <view class="job-content" v-if="item.isOpen">
<view class="j-item" v-for="(job,jIndex) in item.job_list" :key="jIndex"> <view class="j-item" v-for="(job,jIndex) in item.job_list" :key="jIndex"
<view class="j-name" @click="jobSel(item,job)"> @click="jobSel(item,job)">
<view class="j-name">
{{job.dept_name}}-{{job.job_name}} {{job.dept_name}}-{{job.job_name}}
</view> </view>
<image :src="setSelImage(job)" class="image"></image> <image :src="setSelImage(job)" class="image"></image>
...@@ -221,6 +222,7 @@ ...@@ -221,6 +222,7 @@
.job-content { .job-content {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-left: 40rpx;
.j-item { .j-item {
padding: 30rpx 30rpx 0 30rpx; padding: 30rpx 30rpx 0 30rpx;
......
...@@ -4,16 +4,25 @@ ...@@ -4,16 +4,25 @@
<view class="search"> <view class="search">
<view class="search-content"> <view class="search-content">
<image src="../../../static/ic-search.png" class="image"></image> <image src="../../../static/ic-search.png" class="image"></image>
<input placeholder="搜索" placeholder-class="placeholderStyle" @input="search" class="inputStyle" /> <input placeholder="搜索" placeholder-class="placeholderStyle" @input="search" class="inputStyle"
v-model="key" />
</view> </view>
</view> </view>
<view class="org-content"> <ly-tree :tree-data="trees" :props="treeProps" node-key="id" @node-expand="handleNodeExpand"
@node-click="handleNodeClick" :showRadio="true" ref="tree" :defaultCheckedKeys="currentKeys"
:defaultExpandedKeys="currentKeys" childVisibleForFilterNode="true" :filter-node-method="filterNode"
:checkOnClickNode="true" :childVisibleForFilterNode="true">
</ly-tree>
<view class="uni-group-button">
<view class="uni-blue-button" @click="toSwitch">确认切换该组织</view>
</view>
<!-- 暂时处理 -->
<view class="org-content" v-if="false">
<view class="org-list"> <view class="org-list">
<view class="org-item" v-for="(tree,index) in trees" :key="index"> <view class="org-item" v-for="(tree,index) in trees" :key="index">
<view class="org"> <view class="org">
<image <image v-if="isImgShow(tree)" :src="setImgSrc(tree)" class="image"
:src="tree.isOpen?'../../../static/icon_up_arrow.png':'../../../static/icon_drop_arrow.png'" @click="toNextLevel(tree,index)">
class="image" @click="toNextLevel(tree,index)">
</image> </image>
<view class="name" @click="toNextLevel(tree,index)">{{tree.name}}</view> <view class="name" @click="toNextLevel(tree,index)">{{tree.name}}</view>
<view class=" enter" @click="itemClick(tree)">进入</view> <view class=" enter" @click="itemClick(tree)">进入</view>
...@@ -21,10 +30,8 @@ ...@@ -21,10 +30,8 @@
<view v-if="tree.isOpen" style="margin-top: 20rpx;"> <view v-if="tree.isOpen" style="margin-top: 20rpx;">
<view class="org-item" v-for="(oneLevel,oneIndex) in tree.children_list" :key="oneIndex"> <view class="org-item" v-for="(oneLevel,oneIndex) in tree.children_list" :key="oneIndex">
<view class="org"> <view class="org">
<image <image v-if="isImgShow(oneLevel)" :src="setImgSrc(oneLevel)" class="image"
v-if="!oneLevel.project_id&&oneLevel.children_list&&oneLevel.children_list.length>0" @click="toNextChild(index,oneLevel,oneIndex)"></image>
:src="oneLevel.isOpen?'../../../static/icon_up_arrow.png':'../../../static/icon_drop_arrow.png'"
class="image" @click="toNextChild(index,oneLevel,oneIndex)"></image>
<view class="name" @click="toNextChild(index,oneLevel,oneIndex)">{{oneLevel.name}} <view class="name" @click="toNextChild(index,oneLevel,oneIndex)">{{oneLevel.name}}
</view> </view>
<view class="enter" @click="itemClick(oneLevel)">进入</view> <view class="enter" @click="itemClick(oneLevel)">进入</view>
...@@ -51,14 +58,75 @@ ...@@ -51,14 +58,75 @@
export default { export default {
data() { data() {
return { return {
key: "",
trees: [], trees: [],
temp: [] temp: [],
treeProps: function() {
return {
label: 'name', // 指把数据中的‘personName’当做label也就是节点名称
children: 'children_list' // 指
}
},
currentKeys: []
} }
}, },
onLoad() { onLoad() {
var currentId = uni.getStorageSync("org_id")
if (currentId) {
this.currentKeys.push(currentId)
}
console.log("当前选中", this.currentKey);
this.getOrgTree() this.getOrgTree()
}, },
watch: {
key(val) {
this.$refs.tree.filter(val);
}
},
methods: { methods: {
handleNodeClick(obj) {
// console.log('handleNodeClick', obj);
},
handleNodeExpand(obj) {
},
filterNode(value, data) {
if (!value) return true;
// if (!data.label) return false
return data.name.indexOf(value) != -1;
},
toSwitch() {
var node = this.$refs.tree.getCheckedNodes()
if (node.length < 0) {
this.$toast.showToast("请选择切换的组织")
return
}
let that = this
uni.showModal({
title: '提示',
content: '确定切换到该组织?',
showCancel: true,
confirmText: "切换",
confirmColor: '#1890FF',
success: res => {
if (res.confirm) {
that.switchOrg(node[0])
}
}
})
},
setImgSrc(item) {
return item.isOpen ? '../../../static/icon_up_arrow.png' : '../../../static/icon_drop_arrow.png'
},
isImgShow(level) {
if (level.project_id) {
return false
}
if (level.children_list && level.children_list.length > 0) {
return true
}
return false
},
dealProject(list) { dealProject(list) {
var projects = [] var projects = []
list.forEach((item) => { list.forEach((item) => {
...@@ -73,7 +141,8 @@ ...@@ -73,7 +141,8 @@
Api.getOrgTree({ Api.getOrgTree({
data: { data: {
company_id: uni.getStorageSync("company_id"), company_id: uni.getStorageSync("company_id"),
org_no: getApp().globalData.userInfo.user.org_no org_no: getApp().globalData.userInfo.user.org_no,
show_current_level: 1
} }
}).then((result) => { }).then((result) => {
console.log("组织树", result); console.log("组织树", result);
...@@ -85,11 +154,11 @@ ...@@ -85,11 +154,11 @@
item.dept_no == getApp().globalData.userInfo.user.dept_no item.dept_no == getApp().globalData.userInfo.user.dept_no
) )
} else { } else {
if (list[0].no == '001') { // if (list[0].no == '001') {
this.trees = list[0].children_list // this.trees = list[0].children_list
} else { // } else {
this.trees = list this.trees = list
} // }
} }
this.temp = list[0].children_list this.temp = list[0].children_list
} }
...@@ -156,62 +225,63 @@ ...@@ -156,62 +225,63 @@
}) })
}, },
search(e) { search(e) {
var key = e.detail.value // var key = e.detail.value
if (key) { // this.$refs.tree.filter(key, null)
var list = [] // if (key) {
var sourceData = this.temp // var list = []
console.log("数据源", sourceData); // var sourceData = this.temp
sourceData.forEach((item) => { // console.log("数据源", sourceData);
if (item.name.indexOf(key) != -1) { // sourceData.forEach((item) => {
item.isOpen = true // if (item.name.indexOf(key) != -1) {
list.push(item) // item.isOpen = true
} else { // list.push(item)
var children = item.children_list // } else {
var childrens = [] // var children = item.children_list
if (children) { // var childrens = []
children.forEach((child) => { // if (children) {
if (child.name.indexOf(key) != -1) { // children.forEach((child) => {
child.isOpen = true // if (child.name.indexOf(key) != -1) {
var childs = child.children_list // child.isOpen = true
var childList = [] // var childs = child.children_list
if (childs) { // var childList = []
childs.forEach((childItem) => { // if (childs) {
if (childItem.name.indexOf(key) != -1) { // childs.forEach((childItem) => {
childList.push(childItem) // if (childItem.name.indexOf(key) != -1) {
} // childList.push(childItem)
}) // }
} // })
child.children_list = childList // }
childrens.push(child) // child.children_list = childList
} else { // childrens.push(child)
var childs = child.children_list // } else {
var childList = [] // var childs = child.children_list
if (childs) { // var childList = []
childs.forEach((childItem) => { // if (childs) {
if (childItem.name.indexOf(key) != -1) { // childs.forEach((childItem) => {
childList.push(childItem) // if (childItem.name.indexOf(key) != -1) {
} // childList.push(childItem)
}) // }
} // })
if (childList.length > 0) { // }
child.children_list = childList // if (childList.length > 0) {
child.isOpen = true // child.children_list = childList
childrens.push(child) // child.isOpen = true
} // childrens.push(child)
} // }
}) // }
} // })
if (childrens.length > 0) { // }
item.isOpen = true // if (childrens.length > 0) {
item.children_list = childrens // item.isOpen = true
list.push(item) // item.children_list = childrens
} // list.push(item)
} // }
}) // }
this.trees = list // })
} else { // this.trees = list
this.getOrgTree() // } else {
} // this.getOrgTree()
// }
} }
} }
...@@ -227,7 +297,7 @@ ...@@ -227,7 +297,7 @@
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
margin: 30rpx 30rpx 0 30rpx; margin: 30rpx;
.search-content { .search-content {
display: flex; display: flex;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
Please register or to comment