Skip to content

Commit 8c3a549

Browse files
authored
Merge pull request #127 from canyanol650/main
fix 解决重复调用更新设置接口产生的数据异常
2 parents 1ce32cc + 5b80e30 commit 8c3a549

File tree

1 file changed

+72
-76
lines changed

1 file changed

+72
-76
lines changed

vben28/src/views/admin/settings/Setting.vue

+72-76
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,15 @@
1414
<a-input-number v-model:value="setting.value" :min="1" :max="99999" />
1515
</div>
1616
<div v-if="setting.type === 'CheckBox'">
17-
<a-checkbox
18-
:checked="!(setting.value == 'false' || setting.value == false)"
19-
@update:checked="(val) => (setting.value = val)"
20-
>
17+
<a-checkbox :checked="!(setting.value == 'false' || setting.value == false)"
18+
@update:checked="(val) => (setting.value = val)">
2119
</a-checkbox>
2220
{{ setting.description }}
2321
</div>
2422
</a-form-item>
2523

26-
<a-button
27-
style="margin-left: 65%"
28-
type="primary"
29-
@click="updateSettingValues(item.settingItemOutput)"
30-
>{{ t('common.saveText') }}</a-button
31-
>
24+
<a-button style="margin-left: 65%" type="primary" :loading="loading"
25+
@click="updateSettingValues(item.settingItemOutput)">{{ t('common.saveText') }}</a-button>
3226
</a-form>
3327
</CollapseContainer>
3428
</TabPane>
@@ -39,77 +33,79 @@
3933
</template>
4034

4135
<script lang="ts">
42-
import { defineComponent, reactive, toRefs, onMounted } from 'vue';
43-
import { Tabs } from 'ant-design-vue';
44-
import { CollapseContainer, ScrollContainer } from '/@/components/Container/index';
45-
import { SettingOutput, UpdateSettingInput } from '/@/services/ServiceProxies';
46-
import { getAllSettingsAsync, updateSettingsAsync } from '/@/views/admin/settings/Setting';
47-
import { useI18n } from '/@/hooks/web/useI18n';
48-
import { PageWrapper } from '/@/components/Page';
49-
import { message } from 'ant-design-vue';
50-
export default defineComponent({
51-
components: {
52-
ScrollContainer,
53-
CollapseContainer,
54-
Tabs,
55-
TabPane: Tabs.TabPane,
56-
PageWrapper,
57-
},
58-
setup() {
59-
let settingList: SettingOutput[] = [];
60-
const { t } = useI18n();
61-
const state = reactive({
62-
settingList,
63-
loading: true,
64-
});
65-
onMounted(async () => {
36+
import { defineComponent, reactive, toRefs, onMounted } from 'vue';
37+
import { Tabs } from 'ant-design-vue';
38+
import { CollapseContainer, ScrollContainer } from '/@/components/Container/index';
39+
import { SettingOutput, UpdateSettingInput } from '/@/services/ServiceProxies';
40+
import { getAllSettingsAsync, updateSettingsAsync } from '/@/views/admin/settings/Setting';
41+
import { useI18n } from '/@/hooks/web/useI18n';
42+
import { PageWrapper } from '/@/components/Page';
43+
import { message } from 'ant-design-vue';
44+
export default defineComponent({
45+
components: {
46+
ScrollContainer,
47+
CollapseContainer,
48+
Tabs,
49+
TabPane: Tabs.TabPane,
50+
PageWrapper,
51+
},
52+
setup() {
53+
let settingList: SettingOutput[] = [];
54+
const { t } = useI18n();
55+
const state = reactive({
56+
settingList,
57+
loading: true,
58+
});
59+
onMounted(async () => {
60+
state.loading = true;
61+
const result = await getAllSettingsAsync();
62+
state.settingList = result;
63+
state.loading = false;
64+
});
65+
66+
const updateSettingValues = async (item: any) => {
67+
try {
68+
const prefix = 'setting_';
69+
const request = new UpdateSettingInput();
70+
request.values as {};
71+
let items: { [key: string]: string } = {};
72+
item.forEach((e) => {
73+
items[prefix + e.name] = String(e.value);
74+
});
75+
request.values = items;
6676
state.loading = true;
67-
const result = await getAllSettingsAsync();
68-
state.settingList = result;
77+
await updateSettingsAsync({ request });
6978
state.loading = false;
70-
});
71-
72-
const updateSettingValues = async (item: any) => {
73-
try {
74-
const prefix = 'setting_';
75-
const request = new UpdateSettingInput();
76-
request.values as {};
77-
let items: { [key: string]: string } = {};
78-
item.forEach((e) => {
79-
items[prefix + e.name] = String(e.value);
80-
});
81-
request.values = items;
82-
await updateSettingsAsync({ request });
83-
message.success(t('common.operationSuccess'));
84-
} catch (error) {
85-
message.success(t('common.operationFail'));
86-
}
87-
};
88-
return {
89-
prefixCls: 'account-setting',
90-
tabBarStyle: {
91-
width: '220px',
92-
},
93-
labelCol: { span: 4 },
94-
wrapperCol: { span: 14 },
95-
...toRefs(state),
96-
t,
97-
updateSettingValues,
98-
};
99-
},
100-
});
79+
message.success(t('common.operationSuccess'));
80+
} catch (error) {
81+
message.success(t('common.operationFail'));
82+
}
83+
};
84+
return {
85+
prefixCls: 'account-setting',
86+
tabBarStyle: {
87+
width: '220px',
88+
},
89+
labelCol: { span: 4 },
90+
wrapperCol: { span: 14 },
91+
...toRefs(state),
92+
t,
93+
updateSettingValues,
94+
};
95+
},
96+
});
10197
</script>
10298
<style lang="less">
103-
.account-setting {
104-
margin: 12px;
105-
background-color: @component-background;
99+
.account-setting {
100+
margin: 12px;
101+
background-color: @component-background;
106102
107-
.base-title {
108-
padding-left: 0;
109-
}
103+
.base-title {
104+
padding-left: 0;
105+
}
110106
111-
.ant-tabs-tab-active {
112-
background-color: @item-active-bg;
113-
}
107+
.ant-tabs-tab-active {
108+
background-color: @item-active-bg;
114109
}
110+
}
115111
</style>

0 commit comments

Comments
 (0)