mirror of https://github.com/nocodb/nocodb
Wing-Kam Wong
2 years ago
128 changed files with 1595 additions and 1091 deletions
@ -0,0 +1,48 @@
|
||||
import type { MaybeRef } from '@vueuse/core' |
||||
import { computed, unref, useRoute } from '#imports' |
||||
|
||||
export interface CellUrlOptions { |
||||
behavior?: string |
||||
overlay?: string |
||||
} |
||||
|
||||
type ParsedRules = [RegExp, CellUrlOptions] |
||||
|
||||
const parseUrlRules = (serialized?: string): ParsedRules[] | undefined => { |
||||
if (!serialized) return undefined |
||||
|
||||
try { |
||||
return Object.entries(JSON.parse(serialized)).map(([key, value]) => [new RegExp(key), value] as ParsedRules) |
||||
} catch (err) { |
||||
console.error(err) |
||||
|
||||
return undefined |
||||
} |
||||
} |
||||
|
||||
export function useCellUrlConfig(url?: MaybeRef<string>) { |
||||
const route = useRoute() |
||||
|
||||
const config = $computed(() => ({ |
||||
behavior: route.query.url_behavior as string | undefined, |
||||
overlay: route.query.url_overlay as string | undefined, |
||||
rules: parseUrlRules(route.query.url_rules as string), |
||||
})) |
||||
|
||||
const options = computed(() => { |
||||
const options = { behavior: config.behavior, overlay: config.overlay } |
||||
|
||||
if (config.rules && (!config.behavior || !config.overlay)) { |
||||
for (const [regex, value] of config.rules) { |
||||
if (unref(url)?.match(regex)) return Object.assign(options, value) |
||||
} |
||||
} |
||||
|
||||
return options |
||||
}) |
||||
|
||||
return { |
||||
cellUrlConfig: config, |
||||
cellUrlOptions: options, |
||||
} |
||||
} |
@ -0,0 +1,72 @@
|
||||
import { computed, ref } from '#imports' |
||||
|
||||
interface UseLoadingIndicatorProps { |
||||
duration?: number |
||||
throttle?: number |
||||
} |
||||
|
||||
export function useLoadingIndicator({ duration = 2000, throttle = 200 }: UseLoadingIndicatorProps) { |
||||
const progress = ref(0) |
||||
const isLoading = ref(false) |
||||
const step = computed(() => 10000 / duration) |
||||
|
||||
let _timer: any = null |
||||
let _throttle: any = null |
||||
|
||||
function start() { |
||||
clear() |
||||
progress.value = 0 |
||||
isLoading.value = true |
||||
if (throttle) { |
||||
if (process.client) { |
||||
_throttle = setTimeout(_startTimer, throttle) |
||||
} |
||||
} else { |
||||
_startTimer() |
||||
} |
||||
} |
||||
|
||||
function finish() { |
||||
progress.value = 100 |
||||
_hide() |
||||
} |
||||
|
||||
function clear() { |
||||
clearInterval(_timer) |
||||
clearTimeout(_throttle) |
||||
_timer = null |
||||
_throttle = null |
||||
} |
||||
|
||||
function _increase(num: number) { |
||||
progress.value = Math.min(100, progress.value + num) |
||||
} |
||||
|
||||
function _hide() { |
||||
clear() |
||||
if (process.client) { |
||||
setTimeout(() => { |
||||
isLoading.value = false |
||||
setTimeout(() => { |
||||
progress.value = 0 |
||||
}, 400) |
||||
}, 500) |
||||
} |
||||
} |
||||
|
||||
function _startTimer() { |
||||
if (process.client) { |
||||
_timer = setInterval(() => { |
||||
_increase(step.value) |
||||
}, 100) |
||||
} |
||||
} |
||||
|
||||
return { |
||||
progress, |
||||
isLoading, |
||||
start, |
||||
finish, |
||||
clear, |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue