<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>
|