LayerManageSplit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <div
  3. :class="$props.type == 'share' ? '' : 'sm-panel'"
  4. v-show="LayerManageShow"
  5. v-drag
  6. >
  7. <div class="sm-panel-header" v-if="$props.type != 'share'">
  8. <span>{{ Resource.LayerManage }}</span>
  9. <span class="closeBtn" @click="toggleVisibility">&times;</span>
  10. </div>
  11. <Tabs value="">
  12. <TabPane :label="Resource.Resource" name="zyml">
  13. <div class="zyml" :class="$props.splitId >= 0 ? `zymlsplit` : ''">
  14. <div :class="$props.type == 'share' ? 'headerSearch' : 'searchDiv'">
  15. <el-date-picker
  16. placeholder="数据年份"
  17. v-model="treeYearText"
  18. type="year"
  19. format="yyyy"
  20. value-format="yyyy"
  21. popper-class="myDatePicker"
  22. v-if="$props.type == 'share'"
  23. size="small"
  24. ></el-date-picker>
  25. <el-input
  26. :placeholder="Resource.InputPlaceholder"
  27. prefix-icon="el-icon-search"
  28. v-model="treeSearchText"
  29. size="small"
  30. >
  31. </el-input>
  32. <div
  33. class="eicon"
  34. :class="isshowNum ? 'eyes' : 'close_eyes'"
  35. @click="isshowNum = !isshowNum"
  36. ></div>
  37. </div>
  38. <div class="treeDiv">
  39. <el-tree
  40. @check="handleCheckChange"
  41. class="filter-tree"
  42. :data="TreeDatas"
  43. show-checkbox
  44. :props="defaultProps"
  45. :filter-node-method="filterNode"
  46. :default-checked-keys="checkedKeys"
  47. node-key="id"
  48. ref="tree"
  49. >
  50. <span class="custom-tree-node" slot-scope="{ node, data }">
  51. <span>{{
  52. !isshowNum && !data.url && node.label
  53. ? node.label.replace(/\[.*$/, "")
  54. : node.label
  55. }}</span>
  56. <span>
  57. <i
  58. class="el-icon-share"
  59. v-if="data.url != '' && $props.type == 'share'"
  60. @click="showDetail(data)"
  61. ></i>
  62. <Icon
  63. :type="!data.favorite ? 'ios-star-outline' : 'ios-star'"
  64. color="green"
  65. size="18"
  66. class="ivu-icon"
  67. :title="
  68. data.favorite ? Resource.DelCollect : Resource.AddCollect
  69. "
  70. @click="favoriteHandle(data)"
  71. v-if="data.url != ''"
  72. />
  73. </span>
  74. </span>
  75. </el-tree>
  76. </div>
  77. </div>
  78. </TabPane>
  79. <TabPane
  80. :label="Resource.LayerOptions"
  81. name="tckz"
  82. v-if="$props.splitId == -1 || $props.type == 'share'"
  83. >
  84. <div class="tckz">
  85. <List split size="large">
  86. <ListItem v-for="(item, index) in addlayerdata" :key="index">
  87. {{ item.title }}
  88. <div class="listBtn">
  89. <i-switch
  90. v-model="item.visible"
  91. size="small"
  92. @on-change="visibleChange(item, $event)"
  93. >
  94. <template #open>
  95. <span></span>
  96. </template>
  97. <template #close>
  98. <span></span>
  99. </template>
  100. </i-switch>
  101. <Icon
  102. type="md-arrow-round-up"
  103. color="green"
  104. size="18"
  105. class="opBtn"
  106. :title="Resource.MoveUpOneLevel"
  107. @click="raise(item)"
  108. v-if="
  109. index > 0 && (item.type == 'Vector' || item.type == 'IMG')
  110. "
  111. />
  112. <Icon
  113. type="md-arrow-round-down"
  114. color="green"
  115. size="18"
  116. class="opBtn"
  117. :title="Resource.MoveDownOneLevel"
  118. @click="lower(item)"
  119. v-if="
  120. index < addlayerdata.length - 1 &&
  121. (item.type == 'Vector' || item.type == 'IMG')
  122. "
  123. />
  124. <Icon
  125. type="md-locate"
  126. color="green"
  127. size="18"
  128. class="opBtn"
  129. :title="Resource.location"
  130. @click="location(item)"
  131. />
  132. </div>
  133. <div class="sliderBtn" v-if="item.type != 'Terrain'">
  134. <Slider
  135. v-model="item.trans"
  136. @on-change="transSliderChange(item, $event)"
  137. ></Slider>
  138. </div>
  139. </ListItem>
  140. </List>
  141. </div>
  142. </TabPane>
  143. <TabPane :label="Resource.Favorite" name="collect" v-if="$props.type != 'share'">
  144. <div class="collect" :class="$props.splitId >= 0 ? `collectsplit` : ''">
  145. <List split>
  146. <ListItem
  147. v-for="(item, index) in favoriteLayerList"
  148. :key="index"
  149. class="layerlist"
  150. >
  151. <Checkbox
  152. @on-change="checkboxChange(item, $event)"
  153. v-model="item.checked"
  154. >{{ item.title }}</Checkbox
  155. >
  156. <div class="listBtn">
  157. <Icon
  158. type="ios-star"
  159. color="green"
  160. size="18"
  161. class="opBtn"
  162. :title="Resource.DelCollect"
  163. @click="favoriteHandle(item)"
  164. />
  165. </div>
  166. </ListItem>
  167. </List>
  168. </div>
  169. </TabPane>
  170. </Tabs>
  171. </div>
  172. </template>
  173. <script>
  174. import {
  175. Collect,
  176. GetResourceTree,
  177. GetShareTree,
  178. GetMyCollect,
  179. } from "@/api/map";
  180. import { Getservicetype } from "@/views/ResourceShare/myApplication/config.js";
  181. export default {
  182. name: "LayerManageSplit",
  183. props: {
  184. type: {
  185. type: String,
  186. },
  187. splitId: {
  188. type: Number,
  189. default: -1,
  190. },
  191. isshow: {
  192. type: Boolean,
  193. default: false,
  194. },
  195. checkedKeys: {
  196. type: Object,
  197. },
  198. addlayerdata: {
  199. type: Array,
  200. },
  201. },
  202. data() {
  203. return {
  204. addlayerdata: [], //用于双向绑定
  205. defaultProps: {
  206. children: "children",
  207. label: "label",
  208. },
  209. treeSearchText: "",
  210. treeYearText:"",
  211. favoriteLayerList: [],
  212. sharedState: store.state,
  213. TreeDatas: [
  214. {
  215. title: Resource.layerList,
  216. expand: true,
  217. // selected: true,
  218. // contextmenu: true,
  219. children: [],
  220. type: "ROOT",
  221. },
  222. ],
  223. isshowNum: false,
  224. };
  225. },
  226. computed: {
  227. LayerManageShow: function () {
  228. return this.$props.splitId != -1
  229. ? this.$props.isshow
  230. : this.sharedState.toolBar[0];
  231. },
  232. },
  233. methods: {
  234. async showDetail(data) {
  235. console.log(data, "woshidata");
  236. let serverTypeList = await Getservicetype();
  237. serverTypeList.forEach((ty) => {
  238. if (data.type == ty.dictValue) {
  239. data.type = ty.dictLabel;
  240. }
  241. });
  242. console.log(data.serverType, "data.serverType");
  243. this.$emit("updateParent", "isShowService", true);
  244. this.$emit("updateParent", "detailObj", data);
  245. },
  246. toggleVisibility() {
  247. this.$props.splitId != -1
  248. ? this.$emit("close")
  249. : store.setToolBarAction(0);
  250. },
  251. setCheckedKeys(keys) {
  252. this.$refs.tree.setCheckedKeys(keys);
  253. },
  254. filterNode(value, data) {
  255. let addjudge = true;
  256. if (this.$props.type == "split") {
  257. addjudge = data.type !== "Terrain";
  258. } else if (this.$props.type == "roller") {
  259. addjudge = data.type == "IMG" || data.type == "Vector";
  260. }
  261. if (!value) return addjudge;
  262. return data.label.indexOf(value) >= 0 && addjudge;
  263. },
  264. favoriteHandle(data) {
  265. if (data.favorite) {
  266. data.favorite = false;
  267. for (let i = 0; i < this.favoriteLayerList.length; i++) {
  268. if (this.favoriteLayerList[i].id == data.id) {
  269. this.favoriteLayerList.splice(i, 1);
  270. }
  271. }
  272. } else {
  273. data.favorite = true;
  274. this.favoriteLayerList.push(data);
  275. }
  276. Collect(data.id).then((res) => {
  277. if (res.statuscode == 200) {
  278. this.$message({
  279. message: "操作成功",
  280. type: "success",
  281. });
  282. } else {
  283. this.$message.error(res.message);
  284. }
  285. });
  286. },
  287. favorite(data) {
  288. console.log(data);
  289. },
  290. checkboxChange(obj, checked, a) {
  291. obj.checked = checked;
  292. //将收藏中被勾选的数据在资源目录中勾选
  293. let arrData = [];
  294. for (let i = 0; i < this.favoriteLayerList.length; i++) {
  295. if (this.favoriteLayerList[i].checked) {
  296. arrData.push(this.favoriteLayerList[i].id);
  297. }
  298. }
  299. this.$refs.tree.setCheckedKeys(arrData);
  300. this.handleCheckChange(obj, checked);
  301. },
  302. visibleChange(obj, visible, a) {
  303. this.$emit("visibleChange", obj, visible, a);
  304. },
  305. transSliderChange(obj, v, a) {
  306. this.$emit("transSliderChange", obj, v, a);
  307. },
  308. getCheckedNodes() {
  309. if (this.$props.splitId < 0) {
  310. //是否只是叶子节点
  311. let checks = this.$refs.tree.getCheckedNodes(true);
  312. store.setcheckedTreeNode(checks);
  313. }
  314. },
  315. // 复选框改变
  316. handleCheckChange(obj, checked) {
  317. this.getCheckedNodes();
  318. if (typeof checked == "boolean") {
  319. obj.checked = checked;
  320. //添加资源目录与个人收藏来回勾选的状态判断
  321. } else if (obj.checked && checked.checkedKeys.indexOf(obj.id) >= 0) {
  322. obj.checked = obj.checked;
  323. } else {
  324. obj.checked = !obj.checked;
  325. }
  326. //资源目录树选中状态改变,修改个人收藏中的目录页
  327. this.favoriteLayerList.forEach((item) => {
  328. if (item.id == obj.id) {
  329. item.checked = obj.checked;
  330. }
  331. });
  332. this.$emit("handleCheckChange", obj, checked, this.$props.splitId);
  333. },
  334. setDisabledIfChildrenExist(node) {
  335. if (node.children && node.children.length > 0) {
  336. node.disabled = true;
  337. }
  338. // 递归遍历子节点
  339. if (node.children) {
  340. node.children.forEach((child) => {
  341. this.setDisabledIfChildrenExist(child);
  342. });
  343. }
  344. },
  345. //获取后台资源目录树结构
  346. getResourceTree() {
  347. if (this.$props.type == "share") {
  348. this.getShareTree();
  349. } else {
  350. GetResourceTree().then((res) => {
  351. if (res.statuscode == 200) {
  352. // 从根节点开始递归
  353. res.data.forEach((rootNode) => {
  354. this.setDisabledIfChildrenExist(rootNode);
  355. });
  356. this.TreeDatas = res.data;
  357. store.state.tempResourceTree = res.data;
  358. } else {
  359. console.log(res);
  360. }
  361. });
  362. }
  363. },
  364. getShareTree() {
  365. GetShareTree().then((res) => {
  366. if (res.statuscode == 200) {
  367. // 从根节点开始递归
  368. res.data.forEach((rootNode) => {
  369. this.setDisabledIfChildrenExist(rootNode);
  370. });
  371. this.TreeDatas = res.data;
  372. store.state.tempResourceTree = res.data;
  373. } else {
  374. console.log(res);
  375. }
  376. });
  377. },
  378. //获取后台资源目录树结构
  379. getFavoriteLayers() {
  380. GetMyCollect().then((res) => {
  381. if (res.statuscode == 200) {
  382. this.favoriteLayerList = res.data;
  383. } else {
  384. console.log(e);
  385. }
  386. });
  387. },
  388. //图层定位
  389. location(obj) {
  390. this.$emit("location", obj);
  391. },
  392. //影像图层操作
  393. raise(obj) {
  394. this.$emit("raise", obj);
  395. },
  396. lower(obj) {
  397. this.$emit("lower", obj);
  398. },
  399. },
  400. mounted() {
  401. this.getResourceTree();
  402. // this.getShareTree();
  403. this.getFavoriteLayers();
  404. },
  405. watch: {
  406. treeSearchText(val) {
  407. this.$refs.tree.filter(val);
  408. },
  409. treeYearText(val) {
  410. this.$refs.tree.filter(val);
  411. },
  412. LayerManageShow: {
  413. handler() {
  414. if (this.LayerManageShow && this.$props.type) {
  415. setTimeout(() => {
  416. if (this.$refs.tree) this.$refs.tree.filter("");
  417. }, 500);
  418. // this.$nextTick(() => {
  419. // if (this.$refs.tree) this.$refs.tree.filter("");
  420. // });
  421. }
  422. },
  423. immediate: true,
  424. },
  425. addlayerdata(val) {
  426. this.addlayerdata = val;
  427. },
  428. },
  429. };
  430. </script>
  431. <style lang="scss" scoped>
  432. @import "./LayerManage.scss";
  433. .searchDiv {
  434. display: flex;
  435. justify-content: space-between;
  436. margin-right: 10px;
  437. .el-input {
  438. width: calc(100% - 30px);
  439. }
  440. }
  441. .headerSearch {
  442. display: flex;
  443. justify-content: space-between;
  444. margin-right: 10px;
  445. .el-input {
  446. width: 48%;
  447. }
  448. /deep/ .el-input--small .el-input__inner {
  449. color: white !important;
  450. background: rgba(100, 218, 255, 0.1);
  451. border-radius: 2px 10px 2px 10px;
  452. border-color: #5ecef09a;
  453. }
  454. }
  455. // .headerSearch {
  456. // /deep/ .el-form-item{
  457. // // display: flex;
  458. // // justify-content: space-between;
  459. // margin-bottom: 0px;
  460. // }
  461. // /deep/ .el-input{
  462. // width: 90%;
  463. // }
  464. // /deep/ .el-date-picker .el-picker-panel__body .el-year-table td{
  465. // color: #fff !important;
  466. // }
  467. // /deep/ .el-year-table td .cell{
  468. // color: #fff !important;
  469. // }
  470. // /deep/ .el-date-picker__header-label{
  471. // color: #fff !important;
  472. // }
  473. // /deep/ .el-picker-panel__icon-btn{
  474. // color: #fff !important;
  475. // }
  476. // }
  477. </style>