riku
2023-10-31 2d3d56ff801b73afdb779267004d740f9beafe57
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
<template>
  <CloseButton @close="closeEdit">
    <div class="fy-card">
      <div class="fy-h2">正在编辑网格</div>
      <div class="fy-main">
        <el-form
          label-position="left"
          :rules="rules"
          :model="selectedGrid"
          ref="formRef"
        >
          <!-- <el-form-item label="编号" prop="id">
          <div>{{ selectedGrid.id }}</div>
        </el-form-item> -->
          <el-form-item label="名称" prop="name">
            <el-input
              v-model="selectedGrid.name"
              placeholder="请输入网格名称"
              clearable
              disabled
            ></el-input>
          </el-form-item>
          <el-form-item label="顶点" prop="sides">
            <el-scrollbar height="100px" class="fy-main-border">
              <div
                class="list-wrapper"
                v-for="(item, index) in selectedGrid.sides"
                :key="index"
              >
                {{ `${index + 1}. ${item}` }}
              </div>
            </el-scrollbar>
          </el-form-item>
        </el-form>
        <div class="btn-group">
          <el-button
            @click="startOrCompleteEdit"
            :loading="loading"
            >{{ isEdit ? '保存编辑' : '开始编辑' }}</el-button
          >
          <el-button
            type="danger"
            :disabled="!isEdit"
            @click="cancelEdit"
            >取消编辑</el-button
          >
        </div>
      </div>
    </div>
  </CloseButton>
</template>
 
<script>
import { mapState, mapActions } from 'pinia';
import { useGridStore } from '@/stores/grid';
 
export default {
  props: {
    grid: {
      type: Object,
      default: () => {
        return { gName: '' };
      }
    }
  },
  data() {
    return {
      editing: false,
      loading: false
    };
  },
  computed: {
    ...mapState(useGridStore, ['selectedGrid', 'isEdit'])
  },
  methods: {
    ...mapActions(useGridStore, [
      'openGridEdit',
      'closeGridEdit',
      'saveSelectedGrid',
      'quitSelectedGrid',
      'clearSelect'
    ]),
    // 开始或完成保存编辑网格多边形
    startOrCompleteEdit() {
      if (this.isEdit) {
        this.loading = true;
        this.saveSelectedGrid()
          .then(() => {
            this.closeGridEdit();
          })
          .finally(() => (this.loading = false));
      } else {
        this.openGridEdit();
      }
    },
    // 取消编辑网格多边形
    cancelEdit() {
      this.quitSelectedGrid();
      this.closeGridEdit();
    },
    // 关闭编辑界面
    closeEdit() {
      this.cancelEdit();
      this.clearSelect();
    }
  }
};
</script>
<style scoped>
.wrapper {
  /* position: relative;
  background: antiquewhite;
  padding-right: 10px; */
}
.btn-group {
  display: flex;
}
 
.list-wrapper {
  width: 100%;
  /* background-color: var(--el-bg-color-page); */
}
</style>