| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- <template>
- <page-list
- show-tag-filter
- :show-searchbox="true"
- :list="list"
- :columns="columns"
- :group-actions="groupActions"
- :single-actions="singleActions"
- :export-data-options="exportDataOptions" />
- </template>
- <script>
- import expectStatus from '@/constants/expectStatus'
- import WindowsMixin from '@/mixins/windows'
- import ListMixin from '@/mixins/list'
- import {
- getNameFilter,
- getStatusFilter,
- getTenantFilter,
- getDomainFilter,
- getCreatedAtFilter,
- getCustomDistinctFieldFilter,
- getDistinctFieldFilter,
- } from '@/utils/common/tableFilter'
- import { LLM_TYPE_OPTIONS } from '../../llm-sku/llmTypeConfig'
- import SingleActionsMixin from '../mixins/singleActions'
- import ColumnsMixin from '../mixins/columns'
- export default {
- name: 'PhoneList',
- mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
- props: {
- id: String,
- getParams: {
- type: Object,
- },
- },
- data () {
- return {
- list: this.$list.createList(this, {
- id: this.id,
- resource: 'llms',
- getParams: this.getParam,
- steadyStatus: {
- status: (data) => {
- if (Object.values(expectStatus.server).flat().includes(data.status) || Object.values(expectStatus.container).flat().includes(data.llm_status)) {
- return false
- }
- return true
- },
- },
- filterOptions: {
- id: {
- label: this.$t('table.title.id'),
- },
- name: getNameFilter(),
- llm_type: {
- label: this.isApplyType ? this.$t('aice.llm_type.app') : this.$t('aice.llm_type.llm'),
- dropdown: true,
- items: LLM_TYPE_OPTIONS.map(opt => ({ key: opt.id, label: this.$t(opt.name) })),
- },
- status: getStatusFilter('server'),
- llm_ip: {
- label: 'IP',
- filter: true,
- formatter: val => {
- return `llm_ip.contains(${val})`
- },
- },
- host: getCustomDistinctFieldFilter({
- label: this.$t('res.host'),
- field: 'host',
- fetchMethod: this.hostFetcher,
- disabledFormatter: true,
- multiple: false,
- mapper: (list) => {
- return list
- },
- }),
- // no_volume: {
- // label: this.$t('aice.volume_mounted'),
- // dropdown: true,
- // items: [
- // { label: this.$t('compute.text_394'), key: 'false' },
- // { label: this.$t('compute.text_395'), key: 'true' },
- // ],
- // },
- // llm_sku: {
- // label: this.$t('aice.llm_sku'),
- // },
- llm_sku: getDistinctFieldFilter({
- field: 'llm_sku',
- type: 'extra_field',
- label: this.$t('aice.llm_sku'),
- multiple: false,
- }),
- llm_image: {
- label: this.$t('aice.image'),
- },
- projects: getTenantFilter(),
- project_domains: getDomainFilter(),
- created_at: getCreatedAtFilter(),
- },
- hiddenColumns: [],
- fetchDataCb: (response) => {
- this.enrichLlmRowsWithCmpInfo(response)
- },
- }),
- groupActions: [
- {
- label: this.$t('common.create'),
- action: () => {
- this.$router.push(this.isApplyType ? '/app-llm/create' : '/llm/create')
- },
- meta: () => {
- return {
- buttonType: 'primary',
- validate: true,
- }
- },
- },
- // 开机
- {
- label: this.$t('compute.text_272'),
- action: () => {
- this.createDialog('LlmBatchConfirmDialog', {
- data: this.list.selectedItems,
- columns: this.columns,
- onManager: this.onManager,
- action: 'start',
- actionText: this.$t('compute.text_272'),
- steadyStatus: 'running',
- })
- },
- meta: () => {
- let ret = {
- validate: true,
- tooltip: null,
- }
- ret.validate = this.list.selectedItems.length > 0
- if (!ret.validate) return ret
- ret = this.$isValidateResourceLock(this.list.selectedItems, () => {
- ret.validate = this.list.selectedItems.every(item => item.status === 'ready')
- return ret
- })
- return ret
- },
- // hidden: () => this.$isScopedPolicyMenuHidden('vminstance_hidden_menus.server_perform_start'),
- },
- // 重启
- {
- label: this.$t('compute.text_274'),
- permission: 'llms_perform_restart',
- action: () => {
- this.createDialog('LlmBatchConfirmDialog', {
- data: this.list.selectedItems,
- columns: this.columns,
- onManager: this.onManager,
- action: 'restart',
- actionText: this.$t('compute.text_274'),
- steadyStatus: 'running',
- })
- },
- meta: () => {
- let ret = {
- validate: true,
- tooltip: null,
- }
- ret.validate = this.list.selectedItems.length > 0
- if (!ret.validate) return ret
- ret = this.$isValidateResourceLock(this.list.selectedItems, () => {
- ret.validate = this.list.selectedItems.every(item => ['running', 'stop_fail', 'ready'].includes(item.status))
- return ret
- })
- return ret
- },
- },
- // 同步状态
- {
- label: this.$t('common.text00043'),
- action: () => {
- this.onManager('batchPerformAction', {
- steadyStatus: ['running', 'ready'],
- managerArgs: {
- action: 'syncstatus',
- },
- })
- },
- meta: () => {
- return {
- validate: this.list.selectedItems.length > 0,
- }
- },
- },
- /* 批量操作 */
- {
- label: this.$t('compute.text_275'),
- actions: () => {
- return [
- // 更改项目
- {
- label: this.$t('compute.perform_change_owner', [this.$t('dictionary.project')]),
- permission: 'llms_perform_public',
- action: (obj) => {
- this.createDialog('ChangeOwenrDialog', {
- data: this.list.selectedItems,
- columns: this.columns,
- onManager: this.onManager,
- refresh: this.refresh,
- resource: 'llms',
- })
- },
- meta: () => {
- const ret = {
- validate: true,
- tooltip: null,
- }
- ret.validate = this.list.selectedItems.length > 0
- return ret
- },
- },
- // 关机
- {
- label: this.$t('compute.text_273'),
- permission: 'llms_perform_stop',
- action: () => {
- this.createDialog('LlmBatchConfirmDialog', {
- data: this.list.selectedItems,
- columns: this.columns,
- onManager: this.onManager,
- action: 'stop',
- actionText: this.$t('compute.text_273'),
- steadyStatus: 'ready',
- })
- },
- meta: () => {
- let ret = {
- validate: true,
- tooltip: null,
- }
- ret.validate = this.list.selectedItems.length > 0
- if (!ret.validate) return ret
- ret = this.$isValidateResourceLock(this.list.selectedItems, () => {
- ret.validate = this.list.selectedItems.every(item => item.status === 'running')
- return ret
- })
- return ret
- },
- // hidden: () => this.$isScopedPolicyMenuHidden('vminstance_hidden_menus.server_perform_stop'),
- },
- // // 安装秒装应用
- // {
- // label: this.$t('aice.instant_app.install'),
- // action: () => {
- // this.createDialog('PhoneAppInstallConfirmDialog', {
- // vm: this,
- // data: this.list.selectedItems,
- // columns: this.columns,
- // title: this.$t('aice.instant_app.install'),
- // name: this.$t('aice.instant_app'),
- // action: this.$t('aice.instant_app.install'),
- // actionText: this.$t('aice.instant_app.install'),
- // })
- // },
- // meta: () => {
- // let ret = {
- // validate: true,
- // tooltip: null,
- // }
- // ret.validate = this.list.selectedItems.length > 0
- // if (!ret.validate) return ret
- // ret = this.$isValidateResourceLock(this.list.selectedItems, () => {
- // ret.validate = this.list.selectedItems.every(item => ['running', 'ready'].includes(item.status))
- // return ret
- // })
- // return ret
- // },
- // },
- // 删除
- {
- label: this.$t('table.action.delete'),
- action: () => {
- this.createDialog('DeleteResDialog', {
- vm: this,
- data: this.list.selectedItems,
- columns: this.columns,
- title: this.$t('table.action.delete'),
- name: this.$t('aice.llm'),
- onManager: this.onManager,
- })
- },
- meta: () => {
- const ret = { validate: this.list.selected.length }
- if (this.list.selectedItems.some(item => !item.can_delete)) {
- ret.validate = false
- return ret
- }
- return ret
- },
- },
- ]
- },
- },
- ],
- }
- },
- computed: {
- isApplyType () {
- return this.$route.path.includes('app-llm')
- },
- exportDataOptions () {
- return {
- downloadType: 'local',
- title: this.$t('aice.instance'),
- items: [
- { label: 'ID', key: 'id' },
- ...this.columns,
- ],
- }
- },
- },
- created () {
- this.$hM = new this.$Manager('hosts')
- this.serverManager = new this.$Manager('servers')
- this.initSidePageTab('detail')
- this.list.fetchData()
- },
- methods: {
- async enrichLlmRowsWithCmpInfo (response) {
- const rows = response?.data?.data
- if (!Array.isArray(rows) || !rows.length) return
- const params = {
- scope: this.$store.getters.scope,
- }
- const patch = {}
- await Promise.all(
- rows.map(async (row) => {
- if (!row.cmp_id) return
- try {
- const { data } = await this.serverManager.get({ id: row.cmp_id, params })
- if (data) {
- patch[row.id] = { cmp_info: data }
- }
- } catch (e) {
- // 单行失败不影响列表
- }
- }),
- )
- if (this._isDestroyed) return
- if (Object.keys(patch).length) {
- this.list.updatesProperty(patch)
- }
- },
- getParam () {
- const ret = {
- ...this.getParams,
- llm_types: this.isApplyType ? ['dify', 'openclaw', 'comfyui'] : ['vllm', 'ollama'],
- details: true,
- }
- return ret
- },
- async hostFetcher () {
- const params = {
- details: false,
- host_type: 'container',
- field: [
- 'id',
- 'name',
- ],
- }
- const response = await this.$hM.list({ params })
- return {
- data: {
- host: (response.data?.data || []).map(item => item.name),
- },
- }
- },
- handleOpenSidepage (row) {
- this.sidePageTriggerHandle(this, 'LlmSidePage', {
- id: row.id,
- resource: 'llms',
- getParams: this.getParam,
- }, {
- list: this.list,
- })
- },
- },
- }
- </script>
- <style>
- </style>
|