Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzlite
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzlite
提交
b8acb35d
提交
b8acb35d
编写于
10月 27, 2020
作者:
laizhilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
统一代码注释
上级
fc046a0a
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
238 行增加
和
171 行删除
+238
-171
app-treeselect-refreshview.vue
...app-treeselect-refreshview/app-treeselect-refreshview.vue
+238
-171
未找到文件。
app_web/src/components/app-treeselect-refreshview/app-treeselect-refreshview.vue
浏览文件 @
b8acb35d
<
template
>
<div
style=
"margin-right: 16px;"
>
<!--树形下拉框-->
<el-select
:value=
"valueTitle"
:clearable=
"clearable"
@
clear=
"clearHandle"
>
<el-option
:value=
"valueTitle"
:label=
"valueTitle"
:key=
"valueId"
>
<el-tree
id=
"tree-option"
ref=
"selectTree"
:accordion=
"accordion"
:data=
"options"
:props=
"props"
:node-key=
"props.value"
:default-expanded-keys=
"defaultExpandedKey"
@
node-click=
"handleNodeClick"
>
</el-tree>
</el-option>
</el-select>
</div>
<div
style=
"margin-right: 16px;"
>
<!--树形下拉框-->
<el-select
:value=
"valueTitle"
:clearable=
"clearable"
@
clear=
"clearHandle"
>
<el-option
:value=
"valueTitle"
:label=
"valueTitle"
:key=
"valueId"
>
<el-tree
id=
"tree-option"
ref=
"selectTree"
:accordion=
"accordion"
:data=
"options"
:props=
"props"
:node-key=
"props.value"
:default-expanded-keys=
"defaultExpandedKey"
@
node-click=
"handleNodeClick"
>
</el-tree>
</el-option>
</el-select>
</div>
</
template
>
<
script
lang=
"ts"
>
import
{
Vue
,
Component
,
Prop
,
Model
,
Emit
,
Inject
}
from
"vue-property-decorator"
;
import
{
Subject
}
from
"rxjs"
;
@
Component
({})
export
default
class
AppTreeselectRefreshview
extends
Vue
{
// 树数据
public
options
:
any
=
[];
// 树显示说明
public
props
:
any
=
{
value
:
'id'
,
// ID字段名
label
:
'label'
,
// 显示名称
children
:
'apps'
// 子级字段名
};
// 下拉框初始值key
public
valueId
:
any
=
null
;
// 下拉框初始值
public
valueTitle
:
any
=
''
;
// 默认展开节点key
public
defaultExpandedKey
:
any
=
[];
// 是否每次只打开一个同级树节点展开
public
accordion
:
boolean
=
false
;
// 可清空选项
public
clearable
:
boolean
=
true
;
/**
* vue创建
*/
created
():
void
{
}
import
{
Vue
,
Component
,
Prop
,
Model
,
Emit
,
Inject
,
}
from
"vue-property-decorator"
;
import
{
Subject
}
from
"rxjs"
;
/**
* vue挂载
*/
mounted
():
void
{
// 初始化数据
this
.
initHandle
();
}
@
Component
({})
export
default
class
AppTreeselectRefreshview
extends
Vue
{
/**
* 树数据
*
* @type {Array<*>}
* @memberof AppTreeselectRefreshview
*/
public
options
:
any
[]
=
[];
/**
* 获取初始化数据
*/
public
initHandle
()
{
let
url
:
any
=
'/lite/sysapps'
;
this
.
$http
.
get
(
url
).
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
==
200
)
{
const
data
:
any
=
response
.
data
;
if
(
data
&&
data
.
length
>
0
)
{
// 处理数据,生成有相同结构的父子节点结构
let
tempData
:
any
=
[];
data
.
forEach
((
item
:
any
)
=>
{
let
tempItem
:
any
=
item
;
if
(
tempItem
.
pssystemid
)
{
tempItem
.
id
=
tempItem
.
pssystemid
;
tempItem
.
systemId
=
tempItem
.
pssystemid
;
}
if
(
tempItem
.
pssystemname
)
{
tempItem
.
label
=
tempItem
.
pssystemname
;
}
tempData
.
push
(
tempItem
);
});
// 给树赋值
this
.
options
=
tempData
;
// 下拉树
let
tree
:
any
=
this
.
$refs
.
selectTree
;
// 第一个叶子节点
let
firstNode
:
any
=
{};
if
(
tempData
[
0
].
apps
)
{
firstNode
=
tempData
[
0
].
apps
;
}
else
{
firstNode
=
tempData
[
0
];
}
// 从local中拿刷新前选中值
if
(
localStorage
.
getItem
(
'localdata'
))
{
const
localdata
:
any
=
JSON
.
parse
(
localStorage
.
getItem
(
'localdata'
)
as
string
);
this
.
valueId
=
localdata
.
dstappid
;
this
.
valueTitle
=
localdata
.
title
;
this
.
defaultExpandedKey
.
push
(
localdata
.
dstappid
);
// 设置下拉树选中值
tree
.
setCurrentKey
(
localdata
.
dstappid
);
}
else
{
// 设置下拉框默认值
this
.
valueId
=
firstNode
[
0
].
id
;
this
.
valueTitle
=
firstNode
[
0
].
systemId
+
"-"
+
firstNode
[
0
].
label
;
this
.
defaultExpandedKey
.
push
(
firstNode
[
0
].
id
);
// 设置下拉树选中值
tree
.
setCurrentKey
(
firstNode
[
0
].
id
);
}
}
}
else
{
console
.
warn
(
"加载数据错误"
);
}
}).
catch
((
error
:
any
)
=>
{
console
.
warn
(
"加载数据错误,"
+
error
);
})
}
/**
* 树显示说明
*
* @type {*}
* @memberof AppTreeselectRefreshview
*/
public
props
:
any
=
{
value
:
"id"
,
// ID字段名
label
:
"label"
,
// 显示名称
children
:
"apps"
,
// 子级字段名
};
/**
* 注入加载行为
*/
@
Inject
(
"reload"
)
reload
!
:
any
;
/**
* 处理下拉框选中项
*/
public
handleNodeClick
(
node
:
any
)
{
// 父级节点不进行处理
if
(
node
.
apps
)
{
return
;
}
// 从local中拿刷新前选中值
if
(
localStorage
.
getItem
(
'localdata'
))
{
const
localdata
:
any
=
JSON
.
parse
(
localStorage
.
getItem
(
'localdata'
)
as
string
);
if
(
localdata
.
dstappid
==
node
[
this
.
props
.
value
])
{
return
;
}
}
// 重新赋值
this
.
valueId
=
node
[
this
.
props
.
value
];
const
dstsystemid
:
any
=
node
.
systemId
;
this
.
valueTitle
=
dstsystemid
+
"-"
+
node
[
this
.
props
.
label
];
// 添加本地应用数据
const
localdata
:
any
=
{
'dstsystemid'
:
dstsystemid
,
'dstappid'
:
this
.
valueId
,
'title'
:
this
.
valueTitle
};
this
.
$store
.
commit
(
'addLocalData'
,
localdata
);
// 调用App.vue的加载行为
// this.reload();
// 浏览器window的加载行为
window
.
location
.
reload
();
}
/**
* 下拉框初始值的key
*
* @type {*}
* @memberof AppTreeselectRefreshview
*/
public
valueId
:
any
=
null
;
/**
* 清空选中项
*/
public
clearHandle
()
{
this
.
valueId
=
null
;
this
.
valueTitle
=
''
;
this
.
defaultExpandedKey
=
[];
// 清空当前选中节点
let
tree
:
any
=
this
.
$refs
.
selectTree
;
tree
.
setCurrentKey
(
null
);
// 收缩所有节点
this
.
$nextTick
(()
=>
{
for
(
let
i
=
0
;
i
<
this
.
options
.
length
;
i
++
)
{
tree
.
store
.
nodesMap
[
this
.
options
[
i
].
id
].
expanded
=
false
;
}
/**
* 下拉框初始值
*
* @type {*}
* @memberof AppTreeselectRefreshview
*/
public
valueTitle
:
any
=
""
;
/**
* 默认展开节点key
*
* @type {Array<any>}
* @memberof AppTreeselectRefreshview
*/
public
defaultExpandedKey
:
any
[]
=
[];
/**
* 是否每次只打开一个同级树节点展开
*
* @type {boolean}
* @memberof AppTreeselectRefreshview
*/
public
accordion
:
boolean
=
false
;
/**
* 可清空选项
*
* @type {boolean}
* @memberof AppTreeselectRefreshview
*/
public
clearable
:
boolean
=
true
;
/**
* vue创建
*
* @memberof AppTreeselectRefreshview
*/
created
():
void
{}
/**
* vue挂载
*
* @memberof AppTreeselectRefreshview
*/
mounted
():
void
{
// 初始化数据
this
.
initHandle
();
}
/**
* 获取初始化数据
*
* @memberof AppTreeselectRefreshview
*/
public
initHandle
()
{
let
url
:
any
=
"/lite/sysapps"
;
this
.
$http
.
get
(
url
)
.
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
==
200
)
{
const
data
:
any
=
response
.
data
;
if
(
data
&&
data
.
length
>
0
)
{
// 处理数据,生成有相同结构的父子节点结构
let
tempData
:
any
=
[];
data
.
forEach
((
item
:
any
)
=>
{
let
tempItem
:
any
=
item
;
if
(
tempItem
.
pssystemid
)
{
tempItem
.
id
=
tempItem
.
pssystemid
;
tempItem
.
systemId
=
tempItem
.
pssystemid
;
}
if
(
tempItem
.
pssystemname
)
{
tempItem
.
label
=
tempItem
.
pssystemname
;
}
tempData
.
push
(
tempItem
);
});
}
// 给树赋值
this
.
options
=
tempData
;
// 下拉树
let
tree
:
any
=
this
.
$refs
.
selectTree
;
// 第一个叶子节点
let
firstNode
:
any
=
{};
if
(
tempData
[
0
].
apps
)
{
firstNode
=
tempData
[
0
].
apps
;
}
else
{
firstNode
=
tempData
[
0
];
}
/**
* 销毁之前
*/
beforeDestroy
():
void
{
this
.
valueId
=
null
;
this
.
valueTitle
=
''
;
this
.
defaultExpandedKey
=
[];
this
.
options
=
[];
// 从local中拿刷新前选中值
if
(
localStorage
.
getItem
(
"localdata"
))
{
const
localdata
:
any
=
JSON
.
parse
(
localStorage
.
getItem
(
"localdata"
)
as
string
);
this
.
valueId
=
localdata
.
dstappid
;
this
.
valueTitle
=
localdata
.
title
;
this
.
defaultExpandedKey
.
push
(
localdata
.
dstappid
);
// 设置下拉树选中值
tree
.
setCurrentKey
(
localdata
.
dstappid
);
}
else
{
// 设置下拉框默认值
this
.
valueId
=
firstNode
[
0
].
id
;
this
.
valueTitle
=
firstNode
[
0
].
systemId
+
"-"
+
firstNode
[
0
].
label
;
this
.
defaultExpandedKey
.
push
(
firstNode
[
0
].
id
);
// 设置下拉树选中值
tree
.
setCurrentKey
(
firstNode
[
0
].
id
);
}
}
}
else
{
console
.
warn
(
"加载数据错误"
);
}
})
.
catch
((
error
:
any
)
=>
{
console
.
warn
(
"加载数据错误,"
+
typeof
error
==
"string"
?
error
:
JSON
.
stringify
(
error
)
);
});
}
/**
* 注入加载行为
*
* @type {*}
* @memberof AppTreeselectRefreshview
*/
@
Inject
(
"reload"
)
reload
!
:
any
;
/**
* 处理下拉框选中项
*
* @param {*} node 节点对象
* @memberof AppTreeselectRefreshview
*/
public
handleNodeClick
(
node
:
any
)
{
// 父级节点不进行处理
if
(
node
.
apps
)
{
return
;
}
// 从local中拿刷新前选中值
if
(
localStorage
.
getItem
(
"localdata"
))
{
const
localdata
:
any
=
JSON
.
parse
(
localStorage
.
getItem
(
"localdata"
)
as
string
);
if
(
localdata
.
dstappid
==
node
[
this
.
props
.
value
])
{
return
;
}
}
// 重新赋值
this
.
valueId
=
node
[
this
.
props
.
value
];
const
dstsystemid
:
any
=
node
.
systemId
;
this
.
valueTitle
=
dstsystemid
+
"-"
+
node
[
this
.
props
.
label
];
// 添加本地应用数据
const
localdata
:
any
=
{
dstsystemid
:
dstsystemid
,
dstappid
:
this
.
valueId
,
title
:
this
.
valueTitle
,
};
this
.
$store
.
commit
(
"addLocalData"
,
localdata
);
// 调用App.vue的加载行为
// this.reload();
// 浏览器window的加载行为
window
.
location
.
reload
();
}
/**
* 清空选中项
*
* @memberof AppTreeselectRefreshview
*/
public
clearHandle
()
{
this
.
valueId
=
null
;
this
.
valueTitle
=
""
;
this
.
defaultExpandedKey
=
[];
// 清空当前选中节点
let
tree
:
any
=
this
.
$refs
.
selectTree
;
tree
.
setCurrentKey
(
null
);
// 收缩所有节点
this
.
$nextTick
(()
=>
{
for
(
let
i
=
0
;
i
<
this
.
options
.
length
;
i
++
)
{
tree
.
store
.
nodesMap
[
this
.
options
[
i
].
id
].
expanded
=
false
;
}
});
}
/**
* vue销毁之前
*
* @memberof AppTreeselectRefreshview
*/
beforeDestroy
():
void
{
this
.
valueId
=
null
;
this
.
valueTitle
=
""
;
this
.
defaultExpandedKey
=
[];
this
.
options
=
[];
}
}
</
script
>
<
style
lang=
'less'
>
@import "app-treeselect-refreshview.less";
@import "app-treeselect-refreshview.less";
</
style
>
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录