setup()

in dolphinscheduler-ui/src/views/resource/components/resource/index.tsx [64:190]


  setup(props) {
    const router: Router = useRouter()
    const fileStore = useFileStore()
    const breadListRef = ref<Array<string>>()

    const {
      variables,
      tableWidth,
      requestData,
      updateList,
      createColumns,
      handleCreateFile
    } = useTable()

    const userStore = useUserStore()

    variables.resourceType = props.resourceType

    const handleUpdatePage = (page: number) => {
      variables.pagination.page = page
      requestData()
    }

    const handleUpdatePageSize = (pageSize: number) => {
      variables.pagination.page = 1
      variables.pagination.pageSize = pageSize
      requestData()
    }

    const handleConditions = () => {
      requestData()
    }

    const handleCreateFolder = () => {
      variables.folderShowRef = true
    }

    const handleUploadFile = () => {
      variables.isReupload = false
      variables.uploadShowRef = true
    }

    const handleRenameFile = () => {
      variables.renameShowRef = true
    }
    const detailPageStore = useDetailPageStore()
    const isDetailPageStore = useIsDetailPageStore()

    const handleDetailBackList = () => {
      if (isDetailPageStore.getIsDetailPage) {
        variables.resourceType = detailPageStore.getResourceType
        variables.fullName = detailPageStore.getFullName
        variables.tenantCode = detailPageStore.getTenantCode
        variables.searchRef = detailPageStore.getSearchValue
        variables.pagination.page = detailPageStore.getPage
        variables.pagination.pageSize = detailPageStore.getPageSize
        if (!isEmpty(variables.searchRef)) {
          handleConditions()
        }
        detailPageStore.$reset()
        isDetailPageStore.$reset()
      } else {
        detailPageStore.$reset()
        isDetailPageStore.$reset()
      }
    }

    onUnmounted(() => {
      isDetailPageStore.$reset()
    })
    onMounted(() => {
      handleDetailBackList()
      createColumns(variables)
      fileStore.setCurrentDir(variables.fullName)
      breadListRef.value = fileStore.getCurrentDir
        .replace(/\/+$/g, '')
        .split('/')
        .slice(2) as Array<string>
      requestData()
    })

    const trim = getCurrentInstance()?.appContext.config.globalProperties.trim

    const handleBread = (index: number) => {
      const breadName =
        variables.fullName
          .split('/')
          .slice(0, index + 3)
          .join('/') + '/'
      goBread(breadName)
    }

    const goBread = (fullName: string) => {
      const { tenantCode } = variables
      const baseDir = userStore.getBaseResDir
      if (fullName === '' || !fullName.startsWith(baseDir)) {
        router.push({
          name: 'file-manage'
        })
      } else {
        router.push({
          name: 'resource-file-subdirectory',
          query: { prefix: fullName, tenantCode: tenantCode }
        })
      }
    }

    watch(useI18n().locale, () => {
      createColumns(variables)
    })

    return {
      breadListRef,
      tableWidth,
      updateList,
      handleConditions,
      handleCreateFolder,
      handleCreateFile,
      handleUploadFile,
      handleRenameFile,
      handleUpdatePage,
      handleUpdatePageSize,
      handleBread,
      trim,
      ...toRefs(variables)
    }
  },