FormSyncFromZentao.vue 7.4 KB
Newer Older
Z
zhaoke 已提交
1 2 3 4 5
<template>
  <ZModal
    :showModal="showModalRef"
    @onCancel="cancel"
    @onOk="submit"
Z
zhaoke 已提交
6
    :okTitle="okTitle"
Z
zhaoke 已提交
7
    :title="t('sync-from-zentao')"
Z
zhaoke 已提交
8
    :contentStyle="{ width: '600px', overflow: 'hidden' }"
Z
zhaoke 已提交
9
  >
Z
zhaoke 已提交
10
    <Form>
Z
zhaoke 已提交
11
      <FormItem labelWidth="140px" :label="t('module')">
Z
zhaoke 已提交
12
        <select v-model="modelRef.moduleId" @change="fetchCases">
Z
zhaoke 已提交
13 14 15 16 17 18 19
          <option key="" value="">&nbsp;</option>
          <option v-for="item in modules" :key="item.id" :value="item.id">
            <span v-html="item.name"></span>
          </option>
        </select>
      </FormItem>

Z
zhaoke 已提交
20
      <FormItem labelWidth="140px" :label="t('suite')">
Z
zhaoke 已提交
21
        <select v-model="modelRef.suiteId" @change="fetchCases">
Z
zhaoke 已提交
22 23 24 25 26 27 28
          <option key="" value="">&nbsp;</option>
          <option v-for="item in suites" :key="item.id" :value="item.id">
            {{ item.name }}
          </option>
        </select>
      </FormItem>

Z
zhaoke 已提交
29
      <FormItem labelWidth="140px" :label="t('task')">
Z
zhaoke 已提交
30
        <select v-model="modelRef.taskId" @change="fetchCases">
Z
zhaoke 已提交
31 32 33 34 35 36 37
          <option key="" value="">&nbsp;</option>
          <option v-for="item in tasks" :key="item.id" :value="item.id">
            {{ item.name }}
          </option>
        </select>
      </FormItem>

Z
zhaoke 已提交
38
      <FormItem labelWidth="140px" :label="t('lang')">
Z
zhaoke 已提交
39 40 41 42 43 44 45
        <select v-model="modelRef.lang">
          <option v-for="item in langs" :key="item.code" :value="item.code">
            {{ item.name }}
          </option>
        </select>
      </FormItem>

Z
zhaoke 已提交
46
      <FormItem labelWidth="140px" :label="t('save_by_module')">
Z
zhaoke 已提交
47 48 49
        <Switch v-model="modelRef.saveByModule" />
      </FormItem>

Z
zhaoke 已提交
50
      <FormItem labelWidth="140px" :label="t('independent_expect')">
Z
zhaoke 已提交
51 52
        <Switch v-model="modelRef.independentFile" />
      </FormItem>
Z
zhaoke 已提交
53 54 55 56 57 58 59 60 61 62
      <Table
      v-if="cases.length > 0"
      :columns="columns"
      :rows="cases"
      :isHidePaging="true"
      :isSlotMode="true"
      :sortable="{}"
      :hasCheckbox="true"
      :isCheckAll="true"
      @return-checked-rows="onCheckedRows"
Z
zhaoke 已提交
63
      class="table-sync-from-zentao"
Z
zhaoke 已提交
64 65 66 67 68 69 70 71 72
    >
      <template #Type="record">
        {{ t('case_type_' + record.value.Type) }}
      </template>
      <template #LastRunResult="record">
        {{ record.value.LastRunResult == '' ? '' : t(record.value.LastRunResult) }}
      </template>
    </Table>
    <p v-else class="empty-tip">
Z
zhaoke 已提交
73
    {{ tableNotice }}
Z
zhaoke 已提交
74
    </p>
Z
zhaoke 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    </Form>
  </ZModal>
</template>

<script setup lang="ts">
import {
  ref,
  computed,
  defineExpose,
  watch,
  withDefaults,
  defineProps,
  defineEmits,
} from "vue";
import { useI18n } from "vue-i18n";
import { useStore } from "vuex";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
91
import { WorkspaceData } from "../workspace/store";
Z
zhaoke 已提交
92 93 94 95 96 97
import { isWindows } from "@/utils/comm";
import { get as getWorkspace } from "@/views/workspace/service";
import Form from "@/components/Form.vue";
import FormItem from "@/components/FormItem.vue";
import { useForm } from "@/utils/form";
import Switch from "@/components/Switch.vue";
Z
zhaoke 已提交
98
import { ZentaoData } from "@/store/zentao";
Z
zhaoke 已提交
99
import {queryCase} from "@/services/zentao";
Z
zhaoke 已提交
100
import notification from "@/utils/notification";
Z
zhaoke 已提交
101
import Table from "@/components/Table.vue";
Z
zhaoke 已提交
102 103 104 105 106 107 108

export interface FormWorkspaceProps {
  show?: boolean;
  workspaceId?: number;
}
const { t } = useI18n();
const isWin = isWindows();
Z
zhaoke 已提交
109
const disabled = ref(false);
Z
zhaoke 已提交
110 111 112
const props = withDefaults(defineProps<FormWorkspaceProps>(), {
  show: false,
});
Z
zhaoke 已提交
113 114 115
const okTitle = ref(t('confirm'))
const tableNotice = ref(t('loading'))

Z
zhaoke 已提交
116
watch(props, () => {
Z
zhaoke 已提交
117
  if(!props.show) disabled.value = false;
Z
zhaoke 已提交
118 119 120 121 122
  modelRef.value.workspaceId = props.workspaceId;
  selectWorkspace();
});
const modelRef = ref({
  workspaceId: props.workspaceId,
Z
zhaoke 已提交
123
  lang: 'php',
Z
zhaoke 已提交
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
  independentFile: false,
} as any);
const rulesRef = ref({
  workspaceId: [{ required: true, msg: t("pls_select_workspace") }],
  lang: [{ required: true, msg: t("pls_script_lang") }],
});
const { validate, reset, validateInfos } = useForm(modelRef, rulesRef);
watch(props, () => {
  if (!props.show) {
    setTimeout(() => {
      validateInfos.value = {};
    }, 200);
  }
});

const showModalRef = computed(() => {
  return props.show;
});

const emit = defineEmits<{
  (type: "submit", event: {}): void;
  (type: "cancel", event: {}): void;
}>();

const cancel = () => {
  emit("cancel", {});
};

const submit = () => {
Z
zhaoke 已提交
153 154 155 156 157 158
    if(selectedCases.value.length === 0) {
      notification.error({
        message: t("pls_select_co_case"),
      });
      return;
    }
Z
zhaoke 已提交
159 160 161
  if(disabled.value) {
    return;
  }
Z
zhaoke 已提交
162
  okTitle.value = t('syncing');
Z
zhaoke 已提交
163
  disabled.value = true;
Z
zhaoke 已提交
164
  console.log("syncFromZentaoSubmit", console.log(selectedCases.value));
Z
zhaoke 已提交
165
  if (validate()) {
Z
zhaoke 已提交
166
    emit("submit", {caseIds:selectedCases.value, ...modelRef.value});
Z
zhaoke 已提交
167 168 169 170
  }
};

const clearFormData = () => {
Z
zhaoke 已提交
171
  okTitle.value = t('confirm');
Z
zhaoke 已提交
172 173
  modelRef.value = {};
};
aaronchen2k2k's avatar
aaronchen2k2k 已提交
174

Z
zhaoke 已提交
175
const store = useStore<{ Workspace: WorkspaceData, Zentao: ZentaoData }>();
Z
zhaoke 已提交
176 177 178 179 180 181
const currSite = computed<any>(() => store.state.Zentao.currSite);
const currProduct = computed<any>(() => store.state.Zentao.currProduct);
const langs = computed<any[]>(() => store.state.Zentao.langs);
const modules = computed<any[]>(() => store.state.Zentao.modules);
const suites = computed<any[]>(() => store.state.Zentao.suites);
const tasks = computed<any[]>(() => store.state.Zentao.tasks);
Z
zhaoke 已提交
182 183 184 185
const selectedCases = ref([] as number[]);
const cases = ref([]);

const fetchCases = () => {
Z
zhaoke 已提交
186
    tableNotice.value = t('loading');
Z
zhaoke 已提交
187 188 189 190 191
    queryCase({
    siteId: currSite.value.id,
    productId: currProduct.value.id,
    ...modelRef.value,
  }).then((res) => {
Z
zhaoke 已提交
192
    tableNotice.value = t('empty_data');
Z
zhaoke 已提交
193 194 195
    res.data.forEach((item, index) => {
      res.data[index].checked = true;
      selectedCases.value.push(item.Id);
Z
zhaoke 已提交
196 197
    }, (err) => {
        tableNotice.value = t('empty_data');
Z
zhaoke 已提交
198 199 200 201
    });
    cases.value = res.data;
  });
}
Z
zhaoke 已提交
202
const fetchData = () => {
aaronchen2k2k's avatar
aaronchen2k2k 已提交
203 204
  if(currSite.value.id == undefined || currSite.value.id <= 1
      || currProduct.value.id == undefined || currProduct.value.id <= 0) return;
Z
zhaoke 已提交
205 206 207 208 209 210 211 212 213 214 215 216 217
  store.dispatch("Zentao/fetchModules", {
    siteId: currSite.value.id,
    productId: currProduct.value.id,
  });
  store.dispatch("Zentao/fetchSuites", {
    siteId: currSite.value.id,
    productId: currProduct.value.id,
  });
  store.dispatch("Zentao/fetchTasks", {
    siteId: currSite.value.id,
    productId: currProduct.value.id,
  });
};
Z
zhaoke 已提交
218
fetchCases();
Z
zhaoke 已提交
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
fetchData();

watch(
  currProduct,
  () => {
    fetchData();
  },
  { deep: true }
);

watch(
  currSite,
  () => {
    fetchData();
  },
  { deep: true }
);

const selectWorkspace = () => {
  if (0 == modelRef.value.workspaceId) {
    modelRef.value.lang = "";
    return;
  }
  getWorkspace(parseInt(modelRef.value.workspaceId)).then((json) => {
    if (json.code === 0) {
      modelRef.value.lang = json.data.lang;
    }
  });
};
Z
zhaoke 已提交
248
selectWorkspace();
Z
zhaoke 已提交
249

Z
zhaoke 已提交
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
const columns = ref([] as any[]);
const setColumns = () => {
  columns.value = [
    {
      isKey: true,
      label: t("no"),
      field: "Id",
      width: "60px",
    },
    {
      label: t("title"),
      field: "Title",
      width: "60px",
    },
    {
      label: t("type"),
      field: "Type",
      width: "60px",
    },
    {
      label: t("status"),
      field: "StatusName",
      width: "60px",
    },
    {
      label: t("result"),
      field: "LastRunResult",
      width: "60px",
    },
  ];
};
setColumns();

const onCheckedRows = (rows: any[]) => {
    selectedCases.value = rows.map((item) => {
      return parseInt(item);
    });
}

Z
zhaoke 已提交
289 290 291
defineExpose({
  clearFormData,
});
Z
zhaoke 已提交
292 293 294 295 296 297 298 299
</script>

<style>
.table-sync-from-zentao{
    overflow: auto;
    max-height: 50vh;
}
</style>