|
@@ -0,0 +1,173 @@
|
|
|
+<template>
|
|
|
+ <BasicModal
|
|
|
+ width="800px"
|
|
|
+ :title="t('component.upload.choose')"
|
|
|
+ v-bind="$attrs"
|
|
|
+ @register="register"
|
|
|
+ :showOkBtn="false"
|
|
|
+ cancelText="关闭"
|
|
|
+ >
|
|
|
+ <a-button type="primary" preIcon="mdi:reload" iconSize="20" @click="reload" />
|
|
|
+ <a-button class="check-btn" type="success" @click="checked"> 选择 </a-button>
|
|
|
+ <BasicTable ref="tableRef" @register="registerTable" rowKey="id" @rowDbClick="handleDetail">
|
|
|
+ <template #action="{ record, column }">
|
|
|
+ <TableAction :actions="createActions(record, column)" />
|
|
|
+ </template>
|
|
|
+ </BasicTable>
|
|
|
+ </BasicModal>
|
|
|
+</template>
|
|
|
+<script lang="ts">
|
|
|
+ import { defineComponent, PropType, ref, toRefs, unref } from 'vue';
|
|
|
+ import { BasicModal, useModalInner } from '/@/components/Modal';
|
|
|
+ import { adapt } from '/@/utils/adapt';
|
|
|
+ import { useI18n } from '/@/hooks/web/useI18n';
|
|
|
+ import {
|
|
|
+ BasicTable,
|
|
|
+ useTable,
|
|
|
+ TableAction,
|
|
|
+ ActionItem,
|
|
|
+ EditRecordRow,
|
|
|
+ TableActionType,
|
|
|
+ } from '/@/components/Table';
|
|
|
+ import { columns } from './chooseModalData';
|
|
|
+ interface PopupData {
|
|
|
+ title: string;
|
|
|
+ }
|
|
|
+ const formData = [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ username: 'test1',
|
|
|
+ title: '日志1',
|
|
|
+ url: 'http://localhost:3100/#/permission/admin',
|
|
|
+ ip: '0.0.0.0',
|
|
|
+ browser: 'Mozilla/5.0',
|
|
|
+ time: '2020-10-20',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 2,
|
|
|
+ username: 'test2',
|
|
|
+ title: '日志2',
|
|
|
+ url: 'http://localhost:3100/#/permission/admin',
|
|
|
+ ip: '0.0.0.0',
|
|
|
+ browser: 'Mozilla/5.0',
|
|
|
+ time: '2020-10-21',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 3,
|
|
|
+ username: 'test3',
|
|
|
+ title: '日志3',
|
|
|
+ url: 'http://localhost:3100/#/permission/admin',
|
|
|
+ ip: '0.0.0.0',
|
|
|
+ browser: 'Mozilla/5.0',
|
|
|
+ time: '2020-10-21',
|
|
|
+ },
|
|
|
+ ];
|
|
|
+
|
|
|
+ export default defineComponent({
|
|
|
+ components: { BasicModal, BasicTable, TableAction },
|
|
|
+ props: {
|
|
|
+ popupData: {
|
|
|
+ type: Object as PropType<PopupData>,
|
|
|
+ default: () => {},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ setup(props) {
|
|
|
+ const { t } = useI18n();
|
|
|
+ const popupData = props.popupData as PopupData;
|
|
|
+ const tableRef = ref<Nullable<TableActionType>>(null);
|
|
|
+ const currentEditKeyRef = ref('');
|
|
|
+ const modelRef = ref({});
|
|
|
+ const adaptWidth = adapt();
|
|
|
+ const [register] = useModalInner((data) => {
|
|
|
+ // 方式2
|
|
|
+ modelRef.value = data;
|
|
|
+ });
|
|
|
+ const [registerTable] = useTable({
|
|
|
+ // title: '管理员日志',
|
|
|
+ // titleHelpMessage: '',
|
|
|
+ rowSelection: { type: 'checkbox' },
|
|
|
+ columns: columns,
|
|
|
+ clickToRowSelect: false, // 点击行不勾选
|
|
|
+ // api: getUserList,
|
|
|
+ dataSource: formData,
|
|
|
+ actionColumn: {
|
|
|
+ width: 160,
|
|
|
+ title: '操作',
|
|
|
+ dataIndex: 'action',
|
|
|
+ slots: { customRender: 'action' },
|
|
|
+ fixed: undefined,
|
|
|
+ },
|
|
|
+ showIndexColumn: false,
|
|
|
+ bordered: true,
|
|
|
+ });
|
|
|
+ function getTableAction() {
|
|
|
+ // 获取组件
|
|
|
+ const tableAction = unref(tableRef);
|
|
|
+ if (!tableAction) {
|
|
|
+ throw new Error('tableAction is null');
|
|
|
+ }
|
|
|
+ return tableAction;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getSelectRowList() {
|
|
|
+ // 获取选中行
|
|
|
+ console.log(getTableAction().getSelectRows());
|
|
|
+ }
|
|
|
+ function getSelectRowKeyList() {
|
|
|
+ // 获取选中行的key --- id
|
|
|
+ console.log(getTableAction().getSelectRowKeys());
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleChecked(record: EditRecordRow) {
|
|
|
+ currentEditKeyRef.value = record.id; // record.key
|
|
|
+
|
|
|
+ const data = getTableAction().getDataSource();
|
|
|
+ data.map((item) => {
|
|
|
+ if (item.id === record.id) {
|
|
|
+ record = item;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ function checked(record: EditRecordRow) {
|
|
|
+ currentEditKeyRef.value = record.id; // record.key
|
|
|
+
|
|
|
+ const data = getTableAction().getDataSource();
|
|
|
+ data.map((item) => {
|
|
|
+ if (item.id === record.id) {
|
|
|
+ record = item;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function createActions(record: EditRecordRow): ActionItem[] {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ label: '选择',
|
|
|
+ icon: 'akar-icons:eye-open',
|
|
|
+ color: 'success',
|
|
|
+ onClick: handleChecked.bind(null, record),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ register,
|
|
|
+ registerTable,
|
|
|
+ adaptWidth,
|
|
|
+ checked,
|
|
|
+ createActions,
|
|
|
+ getTableAction,
|
|
|
+ getSelectRowList,
|
|
|
+ getSelectRowKeyList,
|
|
|
+ model: modelRef,
|
|
|
+ t,
|
|
|
+ ...toRefs(popupData),
|
|
|
+ };
|
|
|
+ },
|
|
|
+ });
|
|
|
+</script>
|
|
|
+<style lang="less">
|
|
|
+ .check-btn {
|
|
|
+ margin-left: 5px !important;
|
|
|
+ }
|
|
|
+</style>
|