|
@@ -13,10 +13,28 @@
|
|
|
</el-tooltip>
|
|
|
</template>-->
|
|
|
</fs-crud>
|
|
|
+ <el-dialog v-model="importDialogVisible" title="批量导入设备" width="30%">
|
|
|
+ <el-upload
|
|
|
+ ref="uploadRef"
|
|
|
+ :auto-upload="false"
|
|
|
+ :file-list="fileList"
|
|
|
+ :limit="1"
|
|
|
+ :on-change="handleFileChange"
|
|
|
+ :before-upload="() => false"
|
|
|
+ accept=".xls,.xlsx"
|
|
|
+ >
|
|
|
+ <el-button type="primary">选择文件</el-button>
|
|
|
+ </el-upload>
|
|
|
+ <template #footer>
|
|
|
+ <el-button @click="importDialogVisible = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="submitImport">确认导入</el-button>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+
|
|
|
</fs-page>
|
|
|
</template>
|
|
|
<script lang="ts" setup name="device">
|
|
|
-import { onMounted } from 'vue';
|
|
|
+import { onMounted ,ref} from 'vue';
|
|
|
import { useFs} from '@fast-crud/fast-crud';
|
|
|
import { createCrudOptions } from './crud';
|
|
|
import * as api from './api';
|
|
@@ -25,14 +43,79 @@ import * as api from './api';
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
import axios from 'axios'
|
|
|
import Cookies from 'js-cookie';
|
|
|
-import { downloadFile } from '/@/utils/service';
|
|
|
+import { downloadFile,downloadFilePost } from '/@/utils/service';
|
|
|
+import { request } from '/@/utils/service';
|
|
|
|
|
|
const { crudBinding, crudRef, crudExpose, crudOptions, resetCrudOptions } = useFs({ createCrudOptions });
|
|
|
|
|
|
+
|
|
|
+const importDialogVisible = ref(false);
|
|
|
+const fileList = ref<File[]>([]);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
const handleBatchImport = () => {
|
|
|
+ importDialogVisible.value = true;
|
|
|
+};
|
|
|
|
|
|
-}
|
|
|
-const handleExports = () => {
|
|
|
+const handleFileChange = (file: any) => {
|
|
|
+ fileList.value = [file.raw];
|
|
|
+};
|
|
|
+
|
|
|
+const submitImport = async () => {
|
|
|
+ if (fileList.value.length === 0) {
|
|
|
+ ElMessage.warning('请先选择文件');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const rawFile = fileList.value[0];
|
|
|
+ if (!rawFile) {
|
|
|
+ ElMessage.error('文件无效,请重新选择');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('file', rawFile);
|
|
|
+ const token = Cookies.get('token');
|
|
|
+ try {
|
|
|
+ await request({
|
|
|
+ url: '/api/system/device/batch_import/',
|
|
|
+ method: 'post',
|
|
|
+ data: formData,
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'multipart/form-data',
|
|
|
+ "Authorization": token ? `JWT ${token}` : ''
|
|
|
+ }
|
|
|
+ }).then((res: any) => {
|
|
|
+ console.log("导入resssss:::",res)
|
|
|
+ ElMessage.success('导入成功');
|
|
|
+ importDialogVisible.value = false;
|
|
|
+ fileList.value = [];
|
|
|
+ crudExpose.doRefresh();
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('导入失败,请检查文件格式或内容');
|
|
|
+ console.error(error);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+const handleExports = async () => {
|
|
|
+ const selectedRows = (crudExpose as any).selectedIds?.value || [];
|
|
|
+ console.log("selectedRows::",selectedRows)
|
|
|
+ if (selectedRows.length === 0) {
|
|
|
+ ElMessage.warning('请先选择要导出的设备')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ downloadFilePost({
|
|
|
+ url: '/api/system/device/export_selected/',
|
|
|
+ method: 'post',
|
|
|
+ data: {
|
|
|
+ device_ids: selectedRows
|
|
|
+ },
|
|
|
+ filename: '设备导出'
|
|
|
+ })
|
|
|
|
|
|
}
|
|
|
|