CustomModelDialog.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <el-dialog
  3. :title="modelTitle ? modelTitle : '自定义模型'"
  4. :visible="outerDialogVisible"
  5. width="40%"
  6. center
  7. >
  8. <el-dialog
  9. title="请输入模型名称"
  10. width="20%"
  11. :visible="innerDialogVisible"
  12. append-to-body
  13. center
  14. ><div class="model-name">
  15. <div class="model-name-title">名称 :</div>
  16. <el-input v-model="inputName" placeholder="请输入模型名称"></el-input>
  17. </div>
  18. <span slot="footer" class="dialog-footer">
  19. <el-button @click="innerDialogVisible = false">取 消</el-button>
  20. <el-button type="primary" @click="confirm()">确认</el-button>
  21. </span>
  22. </el-dialog>
  23. <el-checkbox-group v-model="checkedList">
  24. <el-checkbox
  25. v-for="item in checkArr"
  26. :key="item"
  27. :label="item"
  28. ></el-checkbox>
  29. </el-checkbox-group>
  30. <span slot="footer" class="dialog-footer">
  31. <input
  32. v-if="overlayBtnShow"
  33. type="button"
  34. value="叠置分析"
  35. class="overlay-btn"
  36. @click="executeOverlay"
  37. />
  38. <el-button @click="clearDialogVisible()">取 消</el-button>
  39. <el-button type="primary" @click="saveModel()">保存模型</el-button>
  40. </span>
  41. </el-dialog>
  42. </template>
  43. <script>
  44. /**
  45. * 底部菜单(自定义模型)组件
  46. * @author: Gao Lu
  47. * @Date: 2022.11.22
  48. */
  49. export default {
  50. name: "CustomModelDialog",
  51. components: {},
  52. data() {
  53. return {
  54. outerDialogVisible: false,
  55. innerDialogVisible: false,
  56. overlayBtnShow: false,
  57. modelTitle: null,
  58. inputName: "自定义模型1",
  59. checkedList: [],
  60. checkArr: [
  61. "永久基本农田",
  62. "建设用地减量化",
  63. "一般耕地种林",
  64. "一般耕地",
  65. "基本农田被违规占用",
  66. "一般耕地抛荒",
  67. "高标准农田",
  68. "一般耕地被违规占用",
  69. "减量化复垦地块后种林",
  70. ],
  71. };
  72. },
  73. watch: {
  74. checkedList(val) {
  75. console.log(val, "checkedList");
  76. },
  77. },
  78. mounted() {
  79. // 监听自定义模型
  80. this.$bus.$on("customModelEvent", () => {
  81. this.customModelEvent();
  82. });
  83. // 监听模型修改事件
  84. this.$bus.$on("updateModel", (node) => {
  85. console.log("监听模型中");
  86. console.log(node, "节点数据");
  87. this.outerDialogVisible = true;
  88. this.checkedList = node.data.data;
  89. this.inputName = node.data.label;
  90. this.overlayBtnShow = true;
  91. this.modelTitle = node.data.label;
  92. this.$store.state.modelStatus = "modify";
  93. });
  94. },
  95. beforeDestroyed() {
  96. // 当容器销毁时,需要停止监听该事件
  97. this.$bus.$off("customModelEvent");
  98. this.$bus.$off("updateModel");
  99. this.overlayBtnShow = false;
  100. },
  101. methods: {
  102. // 弹窗关闭时询问
  103. handleClose() {
  104. // if (this.outerDialogVisible) {
  105. // this.$confirm("").then(() => {
  106. // this.clearDialogVisible();
  107. // });
  108. // }
  109. },
  110. clearDialogVisible() {
  111. this.outerDialogVisible = false;
  112. this.innerDialogVisible = false;
  113. },
  114. // 底部按钮自定义模型事件
  115. customModelEvent() {
  116. this.modelTitle = null;
  117. this.overlayBtnShow = false;
  118. this.$store.state.modelStatus = "create";
  119. this.outerDialogVisible = true;
  120. this.checkedList = [];
  121. this.inputName = "自定义模型1";
  122. },
  123. saveModel() {
  124. if (this.checkedList.length < 2) {
  125. this.$message.info("请至少选择两个类型!");
  126. } else {
  127. if (this.$store.state.modelStatus === "create") {
  128. this.innerDialogVisible = true;
  129. } else {
  130. this.confirm();
  131. }
  132. }
  133. },
  134. confirm() {
  135. this.$confirm("确认保存吗?").then(() => {
  136. this.$message.success("模型以保存");
  137. this.clearDialogVisible();
  138. // modify -- 改变数组类型
  139. if (this.$store.state.modelStatus === "modify") {
  140. this.$store.state.customModelsArr.map((v) => {
  141. if (v.name === this.inputName) {
  142. v.data = this.checkedList;
  143. }
  144. });
  145. }
  146. console.log(this.$store.state.customModelsArr, "先获取的模型数据");
  147. // create -- 创建新的数组
  148. if (this.$store.state.modelStatus === "create") {
  149. this.$store.state.customModelsArr.push({
  150. name: this.inputName,
  151. data: this.checkedList,
  152. });
  153. }
  154. });
  155. },
  156. // 执行叠置分析
  157. executeOverlay() {
  158. alert("正在开发中");
  159. // console.log("execute overlay");
  160. },
  161. },
  162. };
  163. </script>
  164. <style lang="less" scoped>
  165. .model-name {
  166. // pointer-events: auto;
  167. width: 100%;
  168. height: 100%;
  169. display: flex;
  170. &-title {
  171. width: 30%;
  172. height: 100%;
  173. color: #fff;
  174. font-size: 18px;
  175. line-height: 38px;
  176. display: flex;
  177. align-items: center;
  178. justify-content: center;
  179. }
  180. .el-input {
  181. width: 70%;
  182. }
  183. }
  184. .el-checkbox-group {
  185. display: flex;
  186. flex-wrap: wrap;
  187. justify-content: space-around;
  188. }
  189. .el-checkbox {
  190. font-weight: 500;
  191. font-size: 15px;
  192. cursor: pointer;
  193. width: 27%;
  194. height: 30px;
  195. line-height: 30px;
  196. color: #e6e6e6;
  197. margin-right: 0;
  198. }
  199. .overlay-btn {
  200. width: 80px;
  201. height: 40px;
  202. position: absolute;
  203. left: 50px;
  204. bottom: 22px;
  205. border-radius: 4px;
  206. cursor: pointer;
  207. color: #e6e6e6;
  208. border: none;
  209. background: rgba(129, 140, 164, 1);
  210. }
  211. </style>