Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

218 wiersze
6.6 KiB

  1. <template>
  2. <a-card :bordered="false">
  3. <a-spin :spinning="confirmLoading">
  4. <a-tabs tab-position="left">
  5. <a-tab-pane
  6. forceRender
  7. v-for="(group, index) in settingData"
  8. :key="index + 1"
  9. :tab="group.groupDisplayName"
  10. >
  11. <template v-for="(setGroup, gindex) in group.settingInfos">
  12. <a-card :key="gindex" :title="$t(setGroup[0].properties.Group2)">
  13. <a-form
  14. :form="forms[index + '_' + gindex]"
  15. :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }"
  16. @submit="handleSubmit(index + '_' + gindex, $event)"
  17. >
  18. <a-form-item
  19. v-for="settingInfo in setGroup"
  20. :key="settingInfo.name"
  21. :label="$t(settingInfo.displayName)"
  22. >
  23. <a-select
  24. v-if="settingInfo.properties.Type === 'select'"
  25. v-decorator="[
  26. settingInfo.name,
  27. { initialValue: settingInfo.value },
  28. ]"
  29. :placeholder="settingInfo.description"
  30. >
  31. <a-select-option
  32. v-for="(
  33. item, index
  34. ) in settingInfo.properties.Options.split('|')"
  35. :key="index"
  36. :value="item"
  37. >
  38. {{ $t(item) }}
  39. </a-select-option>
  40. </a-select>
  41. <a-checkbox
  42. v-if="settingInfo.properties.Type === 'checkbox'"
  43. v-decorator="[
  44. settingInfo.name,
  45. {
  46. valuePropName: 'checked',
  47. initialValue: settingInfo.value,
  48. },
  49. ]"
  50. :placeholder="settingInfo.description"
  51. />
  52. <a-input
  53. v-if="settingInfo.properties.Type === 'text'"
  54. v-decorator="[
  55. settingInfo.name,
  56. { initialValue: settingInfo.value },
  57. ]"
  58. :placeholder="settingInfo.description"
  59. />
  60. <a-input-number
  61. v-if="settingInfo.properties.Type === 'number'"
  62. v-decorator="[
  63. settingInfo.name,
  64. { initialValue: settingInfo.value },
  65. ]"
  66. :placeholder="settingInfo.description"
  67. />
  68. </a-form-item>
  69. <a-form-item :wrapper-col="{ span: 14, offset: 20 }">
  70. <a-button
  71. type="danger"
  72. @click="resetSetting(index + '_' + gindex)"
  73. >
  74. 重置
  75. </a-button>
  76. <a-button
  77. style="margin-left: 10px"
  78. type="primary"
  79. html-type="submit"
  80. >
  81. 保存
  82. </a-button>
  83. </a-form-item>
  84. </a-form>
  85. </a-card>
  86. </template>
  87. </a-tab-pane>
  88. </a-tabs>
  89. </a-spin>
  90. </a-card>
  91. </template>
  92. <script>
  93. import {
  94. setSettingValues,
  95. resetSettingValues,
  96. get,
  97. } from "@/services/settingManagement/setting";
  98. let that;
  99. export default {
  100. i18n: require('./i18n'),
  101. data() {
  102. return {
  103. labelCol: { span: 7 },
  104. wrapperCol: { span: 10 },
  105. visible: false,
  106. confirmLoading: false,
  107. form: {},
  108. rules: {},
  109. features: "",
  110. forms: {},
  111. settingData: [],
  112. };
  113. },
  114. created() {
  115. that = this;
  116. this.getFormData();
  117. },
  118. methods: {
  119. resetForm() {
  120. this.form = {
  121. defaultConnectionString: "",
  122. };
  123. },
  124. getFormData() {
  125. this.confirmLoading = true;
  126. get()
  127. .then((response) => {
  128. response.map((x, index) => {
  129. x.settingInfos.map((settingInfo, gindex) => {
  130. if (settingInfo.properties.Type === "checkbox") {
  131. settingInfo.value = settingInfo.value === "true" ? true : false;
  132. }
  133. settingInfo.name = settingInfo.name.replace(/\./g, "_");
  134. that.forms[index + "_" + gindex] = that.$form.createForm(that);
  135. });
  136. x.settingInfos = that.groupBy(x.settingInfos, function (item) {
  137. return [item.properties.Group2];
  138. });
  139. });
  140. this.settingData = response;
  141. console.log(this.settingData);
  142. })
  143. .finally(() => {
  144. this.confirmLoading = false;
  145. });
  146. },
  147. handleCancel() {
  148. this.visible = false;
  149. this.currentStep = 0;
  150. },
  151. handleSubmit(index, e) {
  152. e.preventDefault();
  153. this.forms[index].validateFields((err, values) => {
  154. if (!err) {
  155. let newValue = {};
  156. for (let key in values) {
  157. let newKey = "setting_" + key;
  158. newValue[newKey] = values[key].toString();
  159. }
  160. that.confirmLoading = true;
  161. setSettingValues(newValue)
  162. .then(() => {
  163. that.visible = false;
  164. that.$message.info("操作成功");
  165. })
  166. .finally(() => {
  167. that.confirmLoading = false;
  168. });
  169. }
  170. });
  171. },
  172. resetSetting(index) {
  173. that.$confirm({
  174. title: "确定要重置为默认值吗?",
  175. okType: "danger",
  176. onOk() {
  177. that.forms[index].validateFields((err, values) => {
  178. if (!err) {
  179. let newValue = [];
  180. let i=0;
  181. for (let key in values) {
  182. let newKey = key.replace(/_/g, ".");
  183. newValue[i] = newKey;
  184. i++;
  185. }
  186. that.confirmLoading = true;
  187. resetSettingValues(newValue)
  188. .then(() => {
  189. that.visible = false;
  190. that.$message.info("操作成功");
  191. that.getFormData();
  192. })
  193. .finally(() => {
  194. that.confirmLoading = false;
  195. });
  196. }
  197. });
  198. },
  199. });
  200. },
  201. groupBy(array, f) {
  202. let groups = {};
  203. array.forEach(function (o) {
  204. let group = JSON.stringify(f(o));
  205. groups[group] = groups[group] || [];
  206. groups[group].push(o);
  207. });
  208. return Object.keys(groups).map(function (group) {
  209. return groups[group];
  210. });
  211. },
  212. },
  213. };
  214. </script>
  215. <style scoped>
  216. </style>