SettingsModal.vue 4.7 KB
Newer Older
H
Hao Sun 已提交
1
<template>
Z
zhaoke 已提交
2 3 4 5 6 7
<ZModal
    :showModal="props.show"
    :title="t('settings')"
    :contentStyle="{width: '90vw', height: '90vh'}"
    @onCancel="emit('cancel', {event: $event})"
  >
Z
zhaoke 已提交
8
  <div class="site-main space-top space-left space-right">
9 10
    <LanguageSettings></LanguageSettings>
    <p class="divider setting-space-top"></p>
Z
zhaoke 已提交
11
    <div class="t-card-toolbar">
12
      <div class="left strong">
Z
zhaoke 已提交
13
        {{ t("interpreter") }}
Z
zhaoke 已提交
14
      </div>
Z
zhaoke 已提交
15 16 17 18
      <Button class="state primary" size="sm" @click="create()">
        {{ t("create_interpreter") }}
      </Button>
    </div>
Z
zhaoke 已提交
19
    <Table
20
      v-if="interpreters.length > 0"
Z
zhaoke 已提交
21
      :columns="columns"
Z
zhaoke 已提交
22
      :rows="interpreters"
Z
zhaoke 已提交
23 24
      :isHidePaging="true"
      :isSlotMode="true"
25
      :sortable="{}"
Z
zhaoke 已提交
26
    >
Z
zhaoke 已提交
27 28
      <template #lang="record">
        {{ languageMap[record.value.lang].name }}
Z
zhaoke 已提交
29
      </template>
Z
zhaoke 已提交
30

Z
zhaoke 已提交
31
      <template #createdAt="record">
Z
zhaoke 已提交
32
        <span v-if="record.value.createdAt">{{ momentUtc(record.value.createdAt) }}</span>
Z
zhaoke 已提交
33 34 35
      </template>

      <template #action="record">
Z
zhaoke 已提交
36 37 38 39
        <Button @click="() => edit(record)" class="tab-setting-btn" size="sm">{{
          t("edit")
        }}</Button>
        <Button @click="() => remove(record)" class="tab-setting-btn" size="sm"
Z
zhaoke 已提交
40 41
          >{{ t("delete") }}
        </Button>
Z
zhaoke 已提交
42
      </template>
Z
zhaoke 已提交
43
    </Table>
44 45 46
    <p v-else class="empty-tip">
    {{ t("empty_data") }}
    </p>
Z
zhaoke 已提交
47

Z
zhaoke 已提交
48
    <FormInterpreter
Z
zhaoke 已提交
49
      :show="showCreateInterpreterModal"
Z
zhaoke 已提交
50 51
      :info="editInfo"
      @submit="createInterpreter"
Z
zhaoke 已提交
52
      @cancel="modalClose"
Z
zhaoke 已提交
53 54
      ref="formInterpreter"
    />
H
Hao Sun 已提交
55
  </div>
Z
zhaoke 已提交
56
</ZModal>
H
Hao Sun 已提交
57 58 59
</template>

<script setup lang="ts">
Z
zhaoke 已提交
60

aaronchen2k2k's avatar
aaronchen2k2k 已提交
61
import { defineProps, defineEmits, computed, onMounted, ref, watch } from "vue";
Z
zhaoke 已提交
62 63
import { useI18n } from "vue-i18n";
import { momentUtcDef } from "@/utils/datetime";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
64
import Table from "@/components/Table.vue";
Z
zhaoke 已提交
65
import Modal from "@/utils/modal";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
66
import Button from "@/components/Button.vue";
67
import LanguageSettings from "./LanguageSettings.vue";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
68
import {saveInterpreter,listInterpreter, removeInterpreter, getLangSettings} from "@/views/interpreter/service";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
69
import FormInterpreter from "@/views/interpreter/FormInterpreter.vue";
Z
zhaoke 已提交
70 71

const props = defineProps<{
Z
zhaoke 已提交
72 73 74 75 76
  show: boolean;
}>();

const emit = defineEmits<{
    (type: 'cancel', event: {event: any}) : void,
H
Hao Sun 已提交
77
}>();
Z
zhaoke 已提交
78

Z
zhaoke 已提交
79 80 81 82
const { t, locale } = useI18n();
const momentUtc = momentUtcDef;

let interpreters = ref<any>([]);
83

Z
zhaoke 已提交
84
const editInfo = ref(0);
Z
zhaoke 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

onMounted(() => {
  console.log("onMounted");
});

watch(
  locale,
  () => {
    console.log("watch locale", locale);
    setColumns();
  },
  { deep: true }
);

const columns = ref([] as any[]);
const setColumns = () => {
  columns.value = [
    {
      isKey: true,
      label: t("no"),
Z
zhaoke 已提交
105
      field: "id",
106
      width: "60px",
Z
zhaoke 已提交
107 108
    },
    {
Z
zhaoke 已提交
109 110
      label: t("lang"),
      field: "lang",
Z
zhaoke 已提交
111
      width: "60px",
Z
zhaoke 已提交
112 113
    },
    {
Z
zhaoke 已提交
114 115
      label: t("interpreter_path"),
      field: "path",
Z
zhaoke 已提交
116 117 118 119
    },
    {
      label: t("create_time"),
      field: "createdAt",
Z
zhaoke 已提交
120
      width: "160px",
Z
zhaoke 已提交
121 122 123 124
    },
    {
      label: t("opt"),
      field: "action",
Z
zhaoke 已提交
125
      width: "160px",
Z
zhaoke 已提交
126 127 128 129 130
    },
  ];
};
setColumns();

Z
zhaoke 已提交
131
const showCreateInterpreterModal = ref(false);
Z
zhaoke 已提交
132

Z
zhaoke 已提交
133 134 135 136
let languageMap = ref<any>({});
const getInterpretersA = async () => {
  const data = await getLangSettings();
  languageMap.value = data.languageMap;
Z
zhaoke 已提交
137
};
Z
zhaoke 已提交
138
getInterpretersA();
Z
zhaoke 已提交
139 140 141 142 143

onMounted(() => {
  console.log("onMounted");
});

Z
zhaoke 已提交
144 145 146 147 148 149 150 151 152 153 154
const list = () => {
  listInterpreter().then((json) => {
    console.log("---", json);

    if (json.code === 0) {
      interpreters.value = json.data;
    }
  });
};
list();

Z
zhaoke 已提交
155
const create = () => {
Z
zhaoke 已提交
156
  editInfo.value = {};
Z
zhaoke 已提交
157
  showCreateInterpreterModal.value = true;
Z
zhaoke 已提交
158
};
Z
zhaoke 已提交
159 160
const edit = (item) => {
  editInfo.value = item;
Z
zhaoke 已提交
161
  showCreateInterpreterModal.value = true;
Z
zhaoke 已提交
162 163 164
};

const remove = (item) => {
Z
zhaoke 已提交
165
  Modal.confirm({
Z
zhaoke 已提交
166
    title: t("confirm_delete", {
Z
zhaoke 已提交
167 168
      name: languageMap.value[item.value.lang].name,
      typ: t("script_lang"),
Z
zhaoke 已提交
169
    }),
Z
zhaoke 已提交
170
    content: '',
Z
zhaoke 已提交
171 172 173
    okText: t("confirm"),
    cancelText: t("cancel"),
    onOk: async () => {
Z
zhaoke 已提交
174
      await removeInterpreter(item.value.id);
Z
zhaoke 已提交
175
      list();
Z
zhaoke 已提交
176 177 178
    },
  });
};
Z
zhaoke 已提交
179

Z
zhaoke 已提交
180
const modalClose = () => {
Z
zhaoke 已提交
181 182
  showCreateInterpreterModal.value = false;
};
183
const formInterpreter = ref({} as any);
Z
zhaoke 已提交
184 185 186
const createInterpreter = (formData) => {
    saveInterpreter(formData).then((json) => {
        if (json.code === 0) {
187 188 189
          formInterpreter.value.clearFormData();
          showCreateInterpreterModal.value = false;
          list();
Z
zhaoke 已提交
190
        }
191
  }, (json) => {console.log(json)})
Z
zhaoke 已提交
192
};
H
Hao Sun 已提交
193
</script>
Z
zhaoke 已提交
194 195 196 197 198 199 200 201 202 203

<style>
.empty-tip {
  text-align: center;
  padding: 20px 0;
}
.setting-space-top{
    margin-top: 1rem;
}
.t-card-toolbar{
Z
zhaoke 已提交
204 205
    display: flex;
    justify-content: space-between;
Z
zhaoke 已提交
206 207 208
    align-items: flex-end;
    margin-bottom: 1rem;
}
Z
zhaoke 已提交
209 210 211 212 213 214
.tab-setting-btn {
  border: none;
  background: none;
  color: #1890ff;
  border-style: hidden !important;
}
H
Hao Sun 已提交
215
</style>