index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="bm-main-box">
  3. <div class="flex items-center">
  4. <div class="bm-main-box-title">{{ $route.meta.title }}</div>
  5. <div class="ml-auto flex items-center gap-2.5">
  6. <CzrForm class="bm-filter" label-width="0px" @handleEnter="onSearch">
  7. <CzrFormColumn
  8. width="6.68rem"
  9. class="__czr-table-form-column"
  10. :span="24"
  11. label-width="0px"
  12. v-model:param="state.query.form.modeType"
  13. link="select"
  14. :options="DictionaryStore.modelTypes.list"
  15. placeholder="模型类型"
  16. />
  17. <CzrFormColumn
  18. width="6.68rem"
  19. class="__czr-table-form-column"
  20. :span="24"
  21. label-width="0px"
  22. v-model:param="state.query.form.status"
  23. link="select"
  24. :options="DictionaryStore.modelStatus"
  25. placeholder="模型状态"
  26. />
  27. <CzrFormColumn
  28. width="15.63rem"
  29. class="__czr-table-form-column"
  30. :span="24"
  31. label-width="0px"
  32. v-model:param="state.text"
  33. placeholder="输入关键词以检索"
  34. :prefix-icon="Search"
  35. />
  36. <CzrButton type="add" @click="onAdd" />
  37. </CzrForm>
  38. </div>
  39. </div>
  40. <div class="mt-4 flex-1 overflow-hidden" v-loading="state.query.loading">
  41. <CzrTableCard
  42. class="table-card"
  43. :page="state.query.page.pageNum"
  44. :pageSize="state.query.page.pageSize"
  45. :total="state.query.result.total"
  46. :data="state.query.result.data"
  47. @handlePage="onPage"
  48. :col="2"
  49. >
  50. <template #model="{ row, index }">
  51. <div
  52. class="model __hover"
  53. @click="
  54. $router.push({
  55. name: 'd91af45a-7258-4b1e-8e0b-178e8b66d847',
  56. params: {
  57. id: row.id,
  58. },
  59. })
  60. "
  61. >
  62. <div class="flex">
  63. <img
  64. src="@/assets/images/model/model-default-logo.png"
  65. class="mr-2.5 h-[3.25rem] w-[3.25rem]"
  66. />
  67. <div class="flex flex-1 flex-col justify-around overflow-hidden">
  68. <div class="text-[1.25rem] font-bold text-[#2E3238]" v-title>
  69. {{ row.name }}
  70. </div>
  71. <div class="flex">
  72. <div
  73. class="flex h-[1.25rem] items-center justify-center rounded-[0.13rem] bg-gradient-to-r from-[#FF9E2D] to-[#FFB92D] px-[0.38rem] text-[0.63rem] font-bold text-[#ffffff]"
  74. >
  75. {{ DictionaryStore.modelTypes.map.get(row.type) }}
  76. </div>
  77. </div>
  78. </div>
  79. <div class="mt-[0.25rem] ml-auto">
  80. <div
  81. v-if="row.status == 1"
  82. class="flex h-[1.56rem] w-[3.75rem] items-center justify-center rounded-[1.25rem] bg-gradient-to-r from-[#D5F9FE] to-[#E0DAFF] text-[0.75rem] font-bold text-[#1E3F92]"
  83. >
  84. 已启用
  85. </div>
  86. </div>
  87. </div>
  88. <div
  89. class="mt-2.5 mb-auto h-[3rem] text-sm text-[#606266]"
  90. style="line-height: 1.4rem"
  91. v-title="{ lines: 2 }"
  92. >
  93. {{ row.description }}
  94. </div>
  95. <div
  96. class="mt-2 flex items-center gap-2.5 text-[0.75rem] text-[#6F7889]"
  97. >
  98. <div>
  99. {{ DictionaryStore.modelProvides.map.get(row.pluginClass) }}
  100. </div>
  101. <div>|</div>
  102. <div>(创建单位)</div>
  103. <div>|</div>
  104. <div>{{ row.createNickName }}</div>
  105. <div>|</div>
  106. <div>{{ YMDHms(row.updateTime) }}</div>
  107. </div>
  108. <div
  109. class="mt-2 flex items-center gap-2.5 text-[0.75rem] text-[#6F7889]"
  110. >
  111. <div class="ml-auto" @click.capture.stop="onSwitch(row)">
  112. <a-switch
  113. v-model:checked="row.status"
  114. checked-children="启用"
  115. un-checked-children="停用"
  116. :checked-value="1"
  117. :un-checked-value="0"
  118. size="small"
  119. />
  120. </div>
  121. <template v-if="row.status == 0">
  122. <el-tooltip content="编辑" effect="light" placement="top">
  123. <SvgIcon
  124. name="czr_edit"
  125. size="14"
  126. class="__hover"
  127. @click.stop="onEdit(row)"
  128. />
  129. </el-tooltip>
  130. <el-tooltip content="删除" effect="light" placement="top">
  131. <SvgIcon
  132. name="czr_del"
  133. size="16"
  134. class="__hover"
  135. @click.stop="onDel(row)"
  136. />
  137. </el-tooltip>
  138. </template>
  139. </div>
  140. </div>
  141. </template>
  142. </CzrTableCard>
  143. </div>
  144. <detailCom
  145. v-model:show="state.detail.show"
  146. :transfer="state.detail.transfer"
  147. @refresh="onSearch"
  148. />
  149. </div>
  150. </template>
  151. <script setup lang="ts">
  152. import { getCurrentInstance, onMounted, reactive, ref, watch } from 'vue'
  153. import { Search } from '@element-plus/icons-vue'
  154. import { debounce } from 'lodash'
  155. import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
  156. import { ElMessage } from 'element-plus'
  157. import detailCom from './detail.vue'
  158. import {
  159. pluginDel,
  160. pluginGetInstanceList,
  161. pluginUpdateStatus,
  162. } from '@/api/modules/model'
  163. import { YMDHms } from '@/utils/czr-util'
  164. const AppStore = useAppStore()
  165. const DialogStore = useDialogStore()
  166. const DictionaryStore = useDictionaryStore()
  167. const emit = defineEmits([])
  168. const props = defineProps({})
  169. const { proxy }: any = getCurrentInstance()
  170. const state: any = reactive({
  171. text: '',
  172. query: {
  173. init: false,
  174. loading: false,
  175. page: {
  176. pageNum: 1,
  177. pageSize: 20,
  178. },
  179. form: {},
  180. formReal: {},
  181. result: {
  182. total: 0,
  183. data: [],
  184. },
  185. },
  186. detail: {
  187. show: false,
  188. transfer: {},
  189. },
  190. })
  191. const setText = debounce((v) => {
  192. state.query.form.keyword = v
  193. }, 1000)
  194. watch(
  195. () => state.text,
  196. (n) => {
  197. setText(n)
  198. },
  199. )
  200. watch(
  201. () => state.query.form,
  202. (n) => {
  203. if (state.query.init) {
  204. onSearch()
  205. }
  206. },
  207. { deep: true },
  208. )
  209. const onPage = (pageNum, pageSize) => {
  210. setTimeout(() => {
  211. state.query.init = true
  212. }, 100)
  213. state.query.page = {
  214. pageNum: pageNum,
  215. pageSize: pageSize,
  216. }
  217. const params = {
  218. page: state.query.page.pageNum,
  219. size: state.query.page.pageSize,
  220. }
  221. // 添加表单参数
  222. for (const [k, v] of Object.entries(state.query.formReal)) {
  223. if (proxy.$czrUtil.isValue(v)) {
  224. params[k] = v
  225. }
  226. }
  227. state.query.loading = true
  228. pluginGetInstanceList(params)
  229. .then(({ data }: any) => {
  230. state.query.result.total = data.total
  231. state.query.result.data = data.records
  232. })
  233. .catch(() => {})
  234. .finally(() => {
  235. state.query.loading = false
  236. })
  237. }
  238. const onSearch = () => {
  239. state.query.formReal = JSON.parse(JSON.stringify(state.query.form))
  240. onPage(1, state.query.page.pageSize)
  241. }
  242. const onReset = () => {
  243. state.query.page = {
  244. pageNum: 1,
  245. pageSize: 20,
  246. }
  247. state.query.form = {}
  248. onSearch()
  249. }
  250. const onAdd = () => {
  251. state.detail.transfer = {
  252. mode: 'add',
  253. }
  254. state.detail.show = true
  255. }
  256. const onEdit = (row) => {
  257. state.detail.transfer = {
  258. mode: 'edit',
  259. id: row.id,
  260. }
  261. state.detail.show = true
  262. }
  263. const onDel = (row: any) => {
  264. DialogStore.confirm({
  265. title: '删除确认',
  266. content: `${row.p6}个应用正在使用该大模型,删除将导致不可用,请确认是否删除`,
  267. onSubmit: () => {
  268. pluginDel(row.id)
  269. .then(() => {
  270. ElMessage.success('删除成功!')
  271. })
  272. .catch(() => {})
  273. .finally(() => {
  274. onSearch()
  275. })
  276. },
  277. })
  278. }
  279. const onSwitch = (row) => {
  280. if (row.status == 1) {
  281. DialogStore.confirm({
  282. title: '停用确认',
  283. content: `${row.p6}个应用正在使用该大模型,停用将导致不可用,请确认是否停用`,
  284. onSubmit: () => {
  285. pluginUpdateStatus({ ids: [row.id], status: 0 })
  286. .then(() => {
  287. ElMessage.success('停用成功!')
  288. })
  289. .catch(() => {})
  290. .finally(() => {
  291. onSearch()
  292. })
  293. },
  294. onCancel: () => {},
  295. })
  296. } else {
  297. pluginUpdateStatus({ ids: [row.id], status: 1 })
  298. .then(() => {
  299. ElMessage.success('启用成功!')
  300. })
  301. .catch(() => {})
  302. .finally(() => {
  303. onSearch()
  304. })
  305. }
  306. }
  307. onMounted(() => {
  308. initDictionary()
  309. onReset()
  310. })
  311. const initDictionary = () => {
  312. DictionaryStore.initModelTypes()
  313. DictionaryStore.initModelProvides()
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .model {
  318. width: 100%;
  319. background-image: url('@/assets/images/model/model-icon-7.png');
  320. background-repeat: no-repeat;
  321. background-size: 100% 100%;
  322. padding: 1rem 1.5rem;
  323. border-radius: 10px;
  324. box-shadow: 0rem 0.25rem 0.63rem 0rem rgba(40, 83, 247, 0.05);
  325. border: var(--czr-border);
  326. display: flex;
  327. flex-direction: column;
  328. }
  329. </style>