import { defineComponent } from 'vue'
|
import type { Ref } from 'vue'
|
import BaseTable from '@/components/Table/Table'
|
import styles from './Sample.module.scss'
|
import { useSample } from '../../../Controllers/Sample'
|
import IconButton from '@/components/IconButton/IconButton'
|
import SampleDrawer from '../Dialog/SampleDrawer/SampleDrawer'
|
import Search from '@/components/Search/Search'
|
import { columns } from './Config'
|
import TdButton from '@/components/TdButton/TdButton'
|
import { vPermission } from '@/libs/Permission/Permission'
|
|
interface RenderTableType {
|
url?: string
|
dataSource: Ref<any[]>
|
isDrag?: boolean
|
isChecked?: boolean
|
isHidePagination?: boolean
|
params?: Record<string, any>
|
autoHeight?: boolean
|
}
|
|
export default defineComponent({
|
name: 'Sample',
|
directives: {
|
permission: vPermission,
|
},
|
setup(props, ctx) {
|
const {
|
dataSource,
|
contextMenu,
|
dialogConfig,
|
tableRef,
|
current,
|
search,
|
sort,
|
headers,
|
onError,
|
onSearch,
|
onRowClick,
|
onConfirmSample,
|
onCheck,
|
onAddSample,
|
onExport,
|
openDetail,
|
onSuccess,
|
onBeforeUpload,
|
} = useSample(props, ctx)
|
|
/**
|
* @returns 表格
|
*/
|
const RenderBaseTable = (props: RenderTableType) => {
|
const {
|
url,
|
dataSource,
|
isDrag,
|
isChecked,
|
isHidePagination,
|
params,
|
autoHeight,
|
} = props
|
|
return (
|
<div
|
class={{
|
[styles.sampleList]: true,
|
}}
|
>
|
<BaseTable
|
ref={tableRef}
|
url={url}
|
sortUrlTpl="/api/v1/hiawms/sample/{id}/adjustsort/{sort}"
|
v-model:dataSource={dataSource.value}
|
columns={columns}
|
contextMenu={contextMenu}
|
params={params}
|
isDrag={isDrag}
|
isChecked={isChecked}
|
autoHeight={autoHeight}
|
onCheck={onCheck}
|
onRowClick={onRowClick}
|
isHidePagination={isHidePagination}
|
pageSize={50}
|
v-slots={{
|
name: ({ row }: any) => {
|
return row?.name ? (
|
<TdButton
|
onClick={() => openDetail(row)}
|
text={<span style="color:#5a84ff">详情</span>}
|
icon="scale"
|
tip={row?.name}
|
hover
|
>
|
{row?.name}
|
</TdButton>
|
) : (
|
'-'
|
)
|
},
|
}}
|
></BaseTable>
|
</div>
|
)
|
}
|
return () => {
|
return (
|
<div class={styles.sampleContent}>
|
{/* 添加/编辑 */}
|
<SampleDrawer
|
v-model={dialogConfig.visible}
|
title={dialogConfig.title}
|
row={current.value}
|
sort={sort.value}
|
onConfirm={onConfirmSample}
|
/>
|
<div class={styles.headerContent}>
|
<div class={styles.header}>
|
<IconButton
|
v-permission="sample-add"
|
icon="add-p"
|
onClick={onAddSample}
|
type="primary"
|
>
|
添加
|
</IconButton>
|
<el-divider direction="vertical" />
|
<el-upload
|
v-permission="sample-import"
|
name="file"
|
accept=".xlsx,.xls,.csv"
|
show-file-list={false}
|
onError={onError}
|
onSuccess={onSuccess}
|
before-upload={onBeforeUpload}
|
headers={headers.value}
|
action="/api/v1/hiawms/sample/import"
|
>
|
<IconButton icon="in">导入</IconButton>
|
</el-upload>
|
|
<IconButton
|
v-permission="sample-output"
|
icon="out"
|
onClick={onExport}
|
>
|
导出
|
</IconButton>
|
</div>
|
<Search
|
placeholder="请输入关键字"
|
v-model={search.value}
|
onConfirm={onSearch}
|
style={{ marginTop: '-1px' }}
|
/>
|
</div>
|
<RenderBaseTable
|
url="/api/v1/hiawms/sample"
|
dataSource={dataSource}
|
isChecked={true}
|
isDrag={true}
|
/>
|
</div>
|
)
|
}
|
},
|
})
|