zhengyiming
2025-02-10 958b79ed89b9e742540f714a80261d222c0fc09b
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
176
177
178
179
180
181
182
183
184
<template>
  <el-drawer v-model="innerVisible" size="760px" :title="title">
    <el-button style="margin-bottom: 6px" @click="emit('onAddSubModule')">新增</el-button>
    <el-row
      v-if="type != SubModuleType.Column && FastButtonMap[type] && FastButtonMap[type].length > 0"
      style="margin-bottom: 6px"
    >
      <span class="fast-btn-list-label">常用按钮添加: </span>
      <el-button
        v-for="(fastBtn, index) in FastButtonMap[type]"
        :key="index"
        @click="emit('onAddFastBtn', fastBtn)"
        >{{ fastBtn.name }}</el-button
      >
    </el-row>
    <el-row v-if="type === SubModuleType.Column" style="margin-bottom: 6px">
      <el-button @click="openAddInterface">根据interface快速添加</el-button>
    </el-row>
    <el-table :data="innerData" border>
      <el-table-column prop="enCode" label="编号">
        <template #default="{ row }">
          <el-input
            v-if="row.isEdit"
            placeholder="请输入编号"
            v-model.trim="row.enCode"
            autocomplete="off"
          ></el-input>
          <template v-else>{{ row.enCode }} </template>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="名称">
        <template #default="{ row }">
          <el-input
            v-if="row.isEdit"
            placeholder="请输入名称"
            v-model.trim="row.name"
            autocomplete="off"
          ></el-input>
          <template v-else>{{ row.name }} </template>
        </template>
      </el-table-column>
      <el-table-column prop="sortCode" label="排序">
        <template #default="{ row }">
          <el-input-number
            v-if="row.isEdit"
            placeholder="请输入排序"
            controls-position="right"
            :min="0"
            v-model="row.sortCode"
            style="width: 100%"
          ></el-input-number>
          <template v-else> {{ row.sortCode }} </template>
        </template>
      </el-table-column>
      <el-table-column v-if="type === SubModuleType.Column" prop="width" label="数据列宽度">
        <template #default="{ row }">
          <el-input-number
            v-if="row.isEdit"
            placeholder="请输入数据列宽度"
            controls-position="right"
            :min="0"
            :step="10"
            v-model="row.width"
            style="width: 100%"
          ></el-input-number>
          <template v-else> {{ row.width }} </template>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template #default="{ row, $index }">
          <template v-if="row.isEdit">
            <ProTableOperationBtn @click="emit('onSaveSubModule', row)">保存</ProTableOperationBtn>
            <ProTableOperationBtn @click="handleCancel(row, $index)">取消</ProTableOperationBtn>
          </template>
          <template v-else>
            <ProTableOperationBtn @click="row.isEdit = !row.isEdit">编辑</ProTableOperationBtn>
            <ProTableOperationBtn @click="emit('onDeleteSubModule', row)" type="danger"
              >删除</ProTableOperationBtn
            >
          </template>
        </template>
      </el-table-column>
    </el-table>
 
    <el-row v-if="type === SubModuleType.Column" justify="center" style="margin-top: 10px">
      <el-button @click="emit('onBatchSaveColumn')">批量保存</el-button>
    </el-row>
  </el-drawer>
</template>
 
<script setup lang="ts">
import { SubModuleType, FastButtonMap, FastBtn } from '@/constants';
import { ProTableOperationBtn } from '@bole-core/components';
import { Message } from '@/utils';
import { ElMessageBox } from 'element-plus';
 
defineOptions({
  name: 'SubModuleEditDrawer',
});
 
type Props = {
  modelValue: boolean;
  title: string;
  type: SubModuleType;
  data: ValueOf<API.AllSubModule>;
};
 
const props = withDefaults(defineProps<Props>(), {
  modelValue: false,
  title: '',
});
 
const innerData = computed({
  get() {
    return props.data;
  },
  set(val) {
    emit('update:data', val);
  },
});
 
const emit = defineEmits<{
  (e: 'update:modelValue', value: boolean): void;
  (e: 'update:data', data: Props['data']): void;
  (e: 'onAddSubModule'): void;
  //批量添加
  (e: 'onBatchAddColumn', keys: string[]): void;
  (e: 'onAddFastBtn', fastBtn: FastBtn): void;
  (e: 'onSaveSubModule', subModule: API.ModuleButtonDto | API.ModuleColumnDto): void;
  (e: 'onBatchSaveColumn'): void;
  (e: 'onDeleteSubModule', subModule: API.ModuleButtonDto | API.ModuleColumnDto): void;
}>();
 
const innerVisible = computed({
  get() {
    return props.modelValue;
  },
  set(val) {
    emit('update:modelValue', val);
  },
});
 
async function openAddInterface() {
  try {
    let { value } = await ElMessageBox.prompt('请输入interface', '快速添加', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      inputType: 'textarea',
      customClass: 'add-interface-message-box',
    });
    let tmpInput = value.replace(/\?/g, '').replace(/:(.*);/g, ': 1,');
    let json = eval('(' + tmpInput + ')'); //JSON.parse(tmpInput);
    emit('onBatchAddColumn', Object.keys(json));
  } catch (error) {
    console.log('error: ', error);
    if (error === 'cancel') return;
    Message.errorMessage('interface格式错误');
  }
}
 
function handleCancel(row: any, index: number) {
  if (row.id) {
    row.isEdit = !row.isEdit;
  } else {
    //@ts-ignore
    innerData.value = innerData.value.filter((x, i) => i !== index);
  }
}
</script>
 
<style lang="scss">
@use '@/style/common.scss' as *;
 
.fast-btn-list-label {
  line-height: 32px;
  margin-right: 6px;
  color: getCssVar('text-color', 'regular');
}
 
.add-interface-message-box textarea {
  height: 200px;
  resize: none;
}
</style>