lixuliang
2024-04-18 b5c4921d0828500379502a916a2ccf2d9d4acc96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
  <Popup
    ref="pop"
    :title="title"
    :shadow="!isEdit"
    :left="left"
    width="390px"
    @close="close(true)"
    showBtn="true"
    @yes="addData"
    @cancel="close(false)"
  >
    <el-form ref="form" :model="data" :rules="rules" label-width="105px">
      <el-form-item label="名称:">
        <el-input v-model="data.name"></el-input>
      </el-form-item>
      <el-form-item label="地址:" prop="urls">
        <el-input
          v-model="data.urls"
          :title="data.urls"
          :disabled="isEdit"
        ></el-input>
      </el-form-item>
      <el-form-item v-if="showLayer" label="图层名:" prop="layer">
        <el-input v-model="data.layer" :disabled="isEdit"></el-input>
      </el-form-item>
      <el-form-item v-if="showLayer" label="SGS版本:">
        <el-select v-model="vesion" :disabled="isEdit">
          <el-option label="默认" value=""></el-option>
          <el-option label="7.1及更早版本" value="7.1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="showLayer" label="token:">
        <el-input
          v-model="data.token"
          placeholder="可选"
          :disabled="isEdit"
        ></el-input>
      </el-form-item>
      <el-form-item label="图层定位:">
        <el-input v-model="flyTo" placeholder="可选" :title="flyToPosition">
          <i
            slot="suffix"
            class="el-input__icon el-icon-map-location"
            title="获取当前位置"
            @click="getPosition"
          ></i>
        </el-input>
      </el-form-item>
    </el-form>
  </Popup>
</template>
 
<script>
import Popup from "@tools/Popup";
import popupTools from "./mixin/popupTools";
export default {
  name: "AddTerrain",
  components: {
    Popup,
  },
  mixins: [popupTools],
  data() {
    return {
      title: "添加数据",
      left: undefined,
      type: "",
      isEdit: false,
      defaultEditData: undefined,
      data: {
        name: "新增数据",
        urls: "",
        layer: "",
        token: "",
      },
      // 版本
      vesion: "",
      // 表单验证规则
      rules: {
        layer: [{ required: true, message: "请输入图层名", trigger: "blur" }],
        urls: [{ required: true, message: "请输入服务地址", trigger: "blur" }],
      },
    };
  },
  computed: {
    // 是否显示图层名
    showLayer: function () {
      return this.type === "sgsterrain";
    },
  },
  mounted() {},
  methods: {
    // 关闭弹窗
    close(isCloseBtn) {
      // 重置data值
      Object.assign(this.$data, this.$options.data());
      !isCloseBtn && this.$refs.pop.close();
    },
    // 打开弹窗
    open(type, editData, defaultData) {
      this.close(true);
      this.type = type;
      this.isEdit = !!editData;
      if (this.isEdit) {
        this.title = "编辑数据";
        this.left = "calc(100% - 420px)";
 
        // 合并参数
        sgworld.Core.extend(this.data, editData, true, true);
        this.data.id = editData.id;
        // 定位
        editData.flyTo && (this.flyTo = editData.flyTo.join(","));
        this.defaultEditData = editData;
      } else {
        this.title = "添加数据";
        this.data.name = type + "地形";
        if (defaultData) {
          // 合并参数
          sgworld.Core.extend(this.data, defaultData, true, true);
          // 定位
          defaultData.flyTo && (this.flyTo = defaultData.flyTo.join(","));
        }
      }
 
      this.$refs.pop.open();
    },
    // 添加数据
    addData() {
      this.$refs.form.validate((valid) => {
        // 验证通过
        if (valid) {
          let data = {
            id: window.sgworld.Core.getuid(),
            sourceType: this.type + this.vesion,
            ...this.data,
          };
          if (this.flyTo) {
            data.flyTo = this.flyTo.split(",");
          }
 
          if (this.type === "sgsterrain") {
            data.urls += "/Elevation";
          }
 
          // 删除多余值
          if (!this.showLayer) {
            delete data.layer;
            delete data.token;
          }
          this.$emit("success", data, this.isEdit);
 
          this.close();
        }
      });
    },
  },
};
</script>
 
<style scoped lang="less">
.el-form {
  margin-top: 20px;
  margin-right: 10px;
  width: 380px;
 
  /deep/ .el-form-item__label {
    color: #fff;
    font-size: 18px;
  }
 
  /deep/ .el-select {
    width: 100%;
  }
}
</style>