index.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="h-full bg-white">
  3. <fs-crud ref="crudRef" v-bind="crudBinding" />
  4. <n-modal v-model:show="showModal" preset="dialog" title="Dialog">
  5. <template #header>
  6. <div>Excel 文件导入</div>
  7. </template>
  8. <div style="padding: 1rem">
  9. <n-upload
  10. multiple
  11. directory-dnd
  12. :action="uploadFile"
  13. :max="1"
  14. @before-upload="beforeUpload"
  15. @finish="handleFinish"
  16. >
  17. <n-upload-dragger>
  18. <div style="margin-bottom: 12px">
  19. <n-icon size="48" :depth="3">
  20. <archive-icon />
  21. </n-icon>
  22. </div>
  23. <n-text style="font-size: 16px"> 点击或者拖动文件到该区域来上传 </n-text>
  24. <n-p depth="3" style="margin: 8px 0 0 0">
  25. 请不要上传敏感数据,比如你的银行卡号和密码,信用卡号有效期和安全码
  26. </n-p>
  27. </n-upload-dragger>
  28. </n-upload>
  29. </div>
  30. </n-modal>
  31. </div>
  32. </template>
  33. <script setup lang="ts">
  34. import { onMounted, ref } from 'vue';
  35. import type { UploadFileInfo } from 'naive-ui';
  36. import { useFs } from '@fast-crud/fast-crud';
  37. import { getServiceEnvConfig } from '~/.env-config';
  38. import createCrudOptions from './crud';
  39. const { url, proxyPattern } = getServiceEnvConfig(import.meta.env);
  40. const showModal = ref(false);
  41. function openModal() {
  42. showModal.value = true;
  43. }
  44. function closeModal() {
  45. showModal.value = false;
  46. }
  47. const context: any = {
  48. openModal,
  49. closeModal
  50. };
  51. const { crudRef, crudBinding, crudExpose } = useFs({ createCrudOptions, context });
  52. const uploadFile = proxyPattern ? `${proxyPattern}/student/importExcel` : `${url}/student/importExcel`;
  53. function handleFinish() {
  54. crudExpose.doRefresh();
  55. closeModal();
  56. window.$message?.success('上传成功');
  57. }
  58. function beforeUpload(data: { file: UploadFileInfo; fileList: UploadFileInfo[] }) {
  59. if (data.file.file?.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
  60. window.$message?.error('只能上传 Excel 格式的表格文件 请重新上传');
  61. return false;
  62. }
  63. return true;
  64. }
  65. onMounted(() => {
  66. crudExpose.doRefresh();
  67. });
  68. </script>
  69. <style scoped></style>