刘光辉
11 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
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
<script lang="ts" setup>
import type { FormInstance } from 'ant-design-vue';
 
import { computed, nextTick, reactive, ref, toRefs, unref } from 'vue';
 
import { useAttrs, useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { formValidate } from '@jnpf/utils';
 
import { LoadingOutlined } from '@ant-design/icons-vue';
 
import { create, getAiInfo } from '#/api/workFlow/template';
import { colorPredefine } from '#/utils/constants';
 
interface State {
  dataForm: any;
  content: string;
  loading: boolean;
  categoryOptions: any[];
  showForm: boolean;
}
 
const emit = defineEmits(['register', 'reload']);
const { createMessage } = useMessage();
const [registerModal, { changeOkLoading, closeModal }] = useModalInner(init);
const formElRef = ref<FormInstance>();
const state = reactive<State>({
  dataForm: {},
  content: '',
  loading: false,
  categoryOptions: [],
  showForm: false,
});
const { dataForm, content, loading, categoryOptions, showForm } = toRefs(state);
const attrs = useAttrs({ excludeDefaultKeys: false });
const rules = {
  fullName: [{ required: true, message: '必填', trigger: 'blur' }],
  enCode: [{ validator: formValidate('enCode'), trigger: 'blur' }],
  category: [{ required: true, message: '必填', trigger: 'change' }],
  icon: [{ required: true, trigger: 'change', message: '必填' }],
};
const showTypeOptions = [
  { fullName: '都显示', id: 0 },
  { fullName: '仅发起流程显示', id: 1 },
  { fullName: '仅菜单显示', id: 2 },
];
const typeOptions = [{ fullName: '标准流程', id: 0 }];
 
const getBindValue = computed(() => {
  const attr: any = {
    ...unref(attrs),
    title: 'AI建流程',
    okButtonProps: {
      disabled: state.loading,
    },
  };
  if (!state.showForm) attr.footer = null;
  return attr;
});
 
function init(data) {
  state.categoryOptions = data.categoryList || [];
  resetData();
  nextTick(() => {
    formElRef.value?.clearValidate();
  });
}
function resetData() {
  state.content = '';
  state.loading = false;
  state.showForm = false;
  state.dataForm = {};
}
function handleAiSubmit() {
  if (!state.content) return;
  state.loading = true;
  getAiInfo({ keyword: state.content })
    .then((res) => {
      state.showForm = true;
      state.loading = false;
      state.dataForm = { ...state.dataForm, ...res.data };
    })
    .catch(() => {
      state.loading = false;
    });
}
async function handleSubmit() {
  try {
    const values = await formElRef.value?.validate();
    if (!values) return;
    changeOkLoading(true);
    create(state.dataForm)
      .then((res) => {
        changeOkLoading(false);
        closeModal();
        createMessage.success(res.msg);
        emit('reload', { ...state.dataForm, id: res.data });
      })
      .catch(() => {
        changeOkLoading(false);
      });
  } catch {}
}
</script>
<template>
  <BasicModal v-bind="getBindValue" @register="registerModal" @ok="handleSubmit" class="jnpf-ai-create-modal" destroy-on-close>
    <div class="text-tips">通过AI生成流程 ,根据文字描述智能生成推荐流程</div>
    <div class="ai-textarea">
      <jnpf-textarea v-model:value="content" placeholder="输入你的需求描述" :maxlength="100" />
      <div class="ai-button">
        <LoadingOutlined class="mr-[5px]" v-if="loading" />
        <i class="ym-custom ym-custom-send cursor-pointer" :class="{ 'icon-selected': content }" v-else @click="handleAiSubmit"></i>
      </div>
    </div>
    <a-form :colon="false" :label-col="{ style: { width: '77px' } }" :model="dataForm" :rules="rules" ref="formElRef" v-if="showForm">
      <div class="text-tips">流程已生成 ,请继续确认流程名称、编码等配置</div>
      <a-form-item label="流程类型" name="type">
        <jnpf-radio v-model:value="dataForm.type" option-type="button" button-style="solid" :options="typeOptions" />
      </a-form-item>
      <a-form-item label="流程名称" name="fullName">
        <jnpf-input v-model:value="dataForm.fullName" placeholder="请输入" :maxlength="100" />
      </a-form-item>
      <a-form-item label="流程编码" name="enCode">
        <jnpf-input v-model:value="dataForm.enCode" placeholder="请输入" :maxlength="50" />
      </a-form-item>
      <a-form-item label="流程分类" name="category">
        <jnpf-select v-model:value="dataForm.category" :options="categoryOptions" show-search />
      </a-form-item>
      <a-form-item label="流程图标" name="icon">
        <div class="flex">
          <div class="mr-[10px] flex-1">
            <jnpf-icon-picker v-model:value="dataForm.icon" placeholder="请选择" />
          </div>
          <a-form-item-rest>
            <jnpf-color-picker v-model:value="dataForm.iconBackground" size="small" :predefine="colorPredefine" />
          </a-form-item-rest>
        </div>
      </a-form-item>
      <a-form-item label="显示位置" name="showType">
        <jnpf-radio v-model:value="dataForm.showType" option-type="button" button-style="solid" :options="showTypeOptions" />
      </a-form-item>
    </a-form>
  </BasicModal>
</template>