|
@@ -0,0 +1,73 @@
|
|
|
|
+import moment from 'moment';
|
|
|
|
+/**
|
|
|
|
+ * 返回是否为移动端
|
|
|
|
+ * @returns
|
|
|
|
+ */
|
|
|
|
+export const isMobile = (): boolean => {
|
|
|
|
+ const u = navigator.userAgent
|
|
|
|
+ const isPhone = !!u.match(/AppleWebKit.*Mobile.*/) || u.indexOf('iPad') > -1
|
|
|
|
+ return isPhone
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 下载Excel
|
|
|
|
+ * @param data
|
|
|
|
+ * @param type
|
|
|
|
+ * @param fileName
|
|
|
|
+ */
|
|
|
|
+export const downloadFile = (data: BlobPart, type: any, fileName: string) => {
|
|
|
|
+ const blob = new Blob([data], { type: `application/${type};` });
|
|
|
|
+ const downloadElement = document.createElement('a');
|
|
|
|
+ const href = window.URL.createObjectURL(blob);
|
|
|
|
+ downloadElement.href = href;
|
|
|
|
+ downloadElement.download = fileName;
|
|
|
|
+ document.body.appendChild(downloadElement);
|
|
|
|
+ downloadElement.click();
|
|
|
|
+ document.body.removeChild(downloadElement);
|
|
|
|
+ window.URL.revokeObjectURL(href);
|
|
|
|
+}
|
|
|
|
+type Type = "day" | "week" | "month" | "year" | "years" | "y" | "months" | "M" | "weeks" | "w" | "days" | "d" | "hour" | "hours" | "h" | "minute"
|
|
|
|
+type Format = 'YYYY-MM-DD' | 'YYYY-MM-DD HH' | 'YYYY-MM-DD HH:mm' | 'YYYY-MM-DD HH:mm:ss'
|
|
|
|
+export const useAddTime = (num: number, type: Type, format?: Format, date?: Date | string): string => {
|
|
|
|
+ return moment(date || new Date()).add(num, type).format(format || 'YYYY-MM-DD')
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 返回localStorage中的查询参数
|
|
|
|
+ * @param param0
|
|
|
|
+ * @returns
|
|
|
|
+ */
|
|
|
|
+export const getLocalStoragePage = ({
|
|
|
|
+ isSelectPitcherIds,
|
|
|
|
+ isSelctChannelIds,
|
|
|
|
+ isSelectBookNames,
|
|
|
|
+ isDataSelectChannelDisabledPitcher,
|
|
|
|
+ isCostTime,
|
|
|
|
+ isDay1
|
|
|
|
+}: { isSelectPitcherIds?: boolean, isSelctChannelIds?: boolean, isSelectBookNames?: boolean, isDataSelectChannelDisabledPitcher?: boolean, isDay1?: boolean, isCostTime?: boolean }) => {
|
|
|
|
+ const { pitcher_ids, channel_ids, book_names, day1 } = JSON.parse(localStorage.getItem('QUERYFORMNOVEL') || '{}')
|
|
|
|
+ const params: { [x: string]: any } = {}
|
|
|
|
+ if (isSelectPitcherIds && pitcher_ids?.length) {
|
|
|
|
+ params.pitcher_ids = pitcher_ids
|
|
|
|
+ }
|
|
|
|
+ if (isSelctChannelIds && channel_ids?.length) {
|
|
|
|
+ params.channel_ids = channel_ids
|
|
|
|
+ if (isDataSelectChannelDisabledPitcher) {
|
|
|
|
+ delete params?.pitcher_ids
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (isSelectBookNames && book_names?.length) {
|
|
|
|
+ params.book_names = book_names
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isDay1 && day1?.[0]) {
|
|
|
|
+ if (!isCostTime) {
|
|
|
|
+ params.start = day1[0]
|
|
|
|
+ params.end = day1[1]
|
|
|
|
+ } else {
|
|
|
|
+ params.cost_time_start = day1[0]
|
|
|
|
+ params.cost_time_end = day1[1]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return params
|
|
|
|
+}
|