update
init
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* 获取文件、 图片前缀地址
|
||||
* */
|
||||
export const getFileUrl = (url: string) => {
|
||||
const getUrl = sessionStorage.getItem('url');
|
||||
const prefix = `${getUrl}/file/show/${url}`;
|
||||
return prefix;
|
||||
};
|
||||
@@ -0,0 +1,170 @@
|
||||
export function paramsToUrl(url: string, params = {}) {
|
||||
if (typeof params !== 'object' && params == null) {
|
||||
return url;
|
||||
}
|
||||
const searchParams = new URLSearchParams(url.split('?')[1]);
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (typeof value == 'object') {
|
||||
searchParams.set(key, JSON.stringify(value));
|
||||
} else {
|
||||
searchParams.set(key, value);
|
||||
}
|
||||
}
|
||||
return url.split('?')[0] + '?' + searchParams.toString();
|
||||
}
|
||||
|
||||
export function openPage(urlStr: string, params?: any) {
|
||||
if (sessionStorage.getItem('platform')) params['platform'] = sessionStorage.getItem('platform');
|
||||
if (sessionStorage.getItem('module')) params['module'] = sessionStorage.getItem('module');
|
||||
const s = window.location.href;
|
||||
const str = s.includes('mobile') ? s.substring(0, s.indexOf('mobile') + 6) + urlStr + '?' : window.location.origin + urlStr + '?';
|
||||
const url = paramsToUrl(str, params);
|
||||
const link = document.createElement('a');
|
||||
link.style.display = 'none';
|
||||
link.href = url;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
export function newPageParams(params = {}) {
|
||||
return {
|
||||
...params,
|
||||
startNewActivity: params.hasOwnProperty('startNewActivity') ? params.startNewActivity : 1,
|
||||
scheme: sessionStorage.getItem('scheme'),
|
||||
host: sessionStorage.getItem('host'),
|
||||
tokenF: sessionStorage.getItem('tokenF'),
|
||||
...(sessionStorage.getItem('hostAfter') ? { hostAfter: sessionStorage.getItem('hostAfter') } : {}),
|
||||
};
|
||||
}
|
||||
function isValidJSON(jsonString: string) {
|
||||
try {
|
||||
JSON.parse(jsonString);
|
||||
if (typeof JSON.parse(jsonString) === 'number') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function parseQuery(params: any) {
|
||||
if (typeof params !== 'object' && params == null) {
|
||||
return {};
|
||||
}
|
||||
const obj: any = {};
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (isValidJSON(value)) {
|
||||
obj[key] = JSON.parse(value);
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
const ran = navigator.userAgent;
|
||||
const isAndroid = ran.indexOf('Android') > -1 || ran.indexOf('Linux') > -1;
|
||||
const isIOS = !!ran.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
|
||||
// 安卓销毁当前页
|
||||
export function destroyPage() {
|
||||
try {
|
||||
if (isAndroid) {
|
||||
window.android.finishActivity();
|
||||
}
|
||||
if (isIOS) {
|
||||
window.webkit.messageHandlers.finishActivity.postMessage('');
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
export function destroyNewPage(page: any, params = '') {
|
||||
try {
|
||||
if (isAndroid) {
|
||||
window.android[page](params);
|
||||
}
|
||||
if (isIOS) {
|
||||
window.webkit.messageHandlers[page].postMessage(params);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
// 跳转智能穿戴页面
|
||||
export function toIntelligence(date: any) {
|
||||
try {
|
||||
if (isAndroid) {
|
||||
window.android.gotoPreventionOfStroke(date);
|
||||
}
|
||||
if (isIOS) {
|
||||
window.webkit.messageHandlers.gotoPreventionOfStroke.postMessage(date);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
// 横屏
|
||||
export function horizontalPage() {
|
||||
try {
|
||||
if (isAndroid) {
|
||||
window.android.changedConfig('1');
|
||||
}
|
||||
if (isIOS) {
|
||||
window.webkit.messageHandlers.changedConfig.postMessage('1');
|
||||
}
|
||||
if (!sessionStorage.getItem('isMobile')) {
|
||||
window.postMessage({ data: 'landscape' }, '*');
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
// 竖屏
|
||||
export function verticalPage() {
|
||||
try {
|
||||
if (isAndroid) {
|
||||
window.android.changedConfig('2');
|
||||
}
|
||||
if (isIOS) {
|
||||
window.webkit.messageHandlers.changedConfig.postMessage('2');
|
||||
}
|
||||
if (!sessionStorage.getItem('isMobile')) {
|
||||
window.postMessage({ data: 'portrait' }, '*');
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
// 急救培训提交答题数据传给安卓
|
||||
export function setAnswerResult(data: String) {
|
||||
if (isAndroid) {
|
||||
window.android.answerResult(data);
|
||||
}
|
||||
if (isIOS) {
|
||||
window.webkit.messageHandlers.answerResult.postMessage(data);
|
||||
}
|
||||
}
|
||||
// 刷新页面
|
||||
export function refreshPage() {
|
||||
if (isAndroid) {
|
||||
window.android.refreshBeforeWeb();
|
||||
}
|
||||
}
|
||||
// 吃动平衡提交成功
|
||||
export function finishEating() {
|
||||
if (isAndroid) {
|
||||
window.android.finishEvent();
|
||||
}
|
||||
if (isIOS) {
|
||||
window.webkit.messageHandlers.finishEvent.postMessage();
|
||||
}
|
||||
}
|
||||
// 打电话
|
||||
export function setCallPhone(iphoneData: string) {
|
||||
if (isAndroid) {
|
||||
window.android.callPhone(iphoneData);
|
||||
}
|
||||
if (isIOS) {
|
||||
window.webkit.messageHandlers.callPhone.postMessage(iphoneData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 拦截安卓返回方法
|
||||
/*
|
||||
* type 1使用拦截,0取消拦截 返回值提供给安卓使用
|
||||
* 配合 affirmBack: 1使用,
|
||||
* 使用方法:需要在跳转前参数添加affirmBack: 1,才有效果
|
||||
* */
|
||||
export function useInterceptBack(type: string, fun = function a() {}) {
|
||||
window.interceptBack = () => {
|
||||
if (fun && typeof fun == 'function') {
|
||||
fun();
|
||||
}
|
||||
return type;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
interface TabHooks {
|
||||
activeTab: number;
|
||||
setActiveTab: (index: number) => void;
|
||||
}
|
||||
|
||||
// 1.切换tab
|
||||
export const useTabHooks = (initialTab: number): TabHooks => {
|
||||
const activeTab = ref(initialTab);
|
||||
|
||||
const setActiveTab = (index: number) => {
|
||||
activeTab.value = index;
|
||||
};
|
||||
|
||||
return {
|
||||
activeTab,
|
||||
setActiveTab,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,145 @@
|
||||
import moment from 'moment';
|
||||
import { toInteger } from 'lodash-es';
|
||||
|
||||
//1.生成 A 到 Z 的数组
|
||||
export function generateArrayUpper() {
|
||||
const arrGenerate = [];
|
||||
for (let i = 0; i < 26; i++) {
|
||||
const letter = String.fromCharCode(65 + i);
|
||||
arrGenerate.push(letter);
|
||||
}
|
||||
return arrGenerate;
|
||||
}
|
||||
|
||||
// 2.去掉末尾的特殊符号
|
||||
export function removeSign(str: string, sign: string) {
|
||||
if (!str) return '';
|
||||
if (str.endsWith(sign)) {
|
||||
str = str.slice(0, -1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
//3.正确答案
|
||||
export const correctText = (data) => {
|
||||
if (!data) return '';
|
||||
let str = '';
|
||||
const No = generateArrayUpper();
|
||||
const { optionVoList } = data;
|
||||
if (!optionVoList) return;
|
||||
optionVoList.forEach((item, i) => {
|
||||
if (item.qsScore !== 0) {
|
||||
str += No[i] + ',';
|
||||
}
|
||||
});
|
||||
return removeSign(str, ',');
|
||||
};
|
||||
//4.当前选择答案
|
||||
export const chooseText = (data) => {
|
||||
if (!data) return '';
|
||||
let str = '';
|
||||
const No = generateArrayUpper();
|
||||
const { optionVoList, chooseOption } = data;
|
||||
if (!optionVoList) return;
|
||||
optionVoList.forEach((item, i) => {
|
||||
if (chooseOption.includes(item.qsOptionCode)) {
|
||||
str += No[i] + ',';
|
||||
}
|
||||
});
|
||||
return removeSign(str, ',');
|
||||
};
|
||||
|
||||
//5.格式化时间
|
||||
export function timeFormat(date, type = 'YYYY-MM-DD HH:mm:ss') {
|
||||
if (!date) return '';
|
||||
return moment(date).format(type);
|
||||
}
|
||||
|
||||
export const weekTime = 86400000 * 6;
|
||||
export const day7 = 86400000 * 7;
|
||||
|
||||
//6.获取当前周一周日
|
||||
export function getMondayDate() {
|
||||
const current = new Date();
|
||||
const a = new Date(current.getFullYear(), current.getMonth(), current.getDate() - current.getDay() + 1);
|
||||
const firstDay = current.getDay() == 0 ? new Date(timeFormat(a.getTime() - day7)) : a;
|
||||
const lastDay = timeFormat(firstDay.getTime() + weekTime);
|
||||
return [timeFormat(firstDay, 'YYYY-MM-DD'), timeFormat(lastDay, 'YYYY-MM-DD')];
|
||||
}
|
||||
|
||||
//7.获取指定周一周日 time:周一时间
|
||||
export function getChooseWeek(time) {
|
||||
const current = new Date(time);
|
||||
const firstDay = new Date(current.getFullYear(), current.getMonth(), current.getDate() - current.getDay() + 1);
|
||||
const lastDay = timeFormat(firstDay.getTime() + weekTime);
|
||||
return [timeFormat(firstDay, 'YYYY-MM-DD'), timeFormat(lastDay, 'YYYY-MM-DD')];
|
||||
}
|
||||
|
||||
// 8.获取月份
|
||||
export function getMonth(time) {
|
||||
const current = new Date(time);
|
||||
return timeFormat(current, 'YYYY-MM');
|
||||
}
|
||||
|
||||
//9.判断对象中是否全部不为空
|
||||
export function checkValues(obj) {
|
||||
// 如果obj是一个对象
|
||||
if (typeof obj === 'object' && obj !== null) {
|
||||
// 遍历对象的所有键
|
||||
for (const key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
// 如果键值是对象,则递归调用
|
||||
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
||||
if (!checkValues(obj[key])) {
|
||||
return false;
|
||||
}
|
||||
} else if (!obj[key]) {
|
||||
// 如果键值是空的(null, undefined, 0, false, NaN, '')
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!obj) {
|
||||
return false;
|
||||
}
|
||||
// 如果所有的值都不为空,返回true
|
||||
return true;
|
||||
}
|
||||
|
||||
// 10.转换为整数
|
||||
export function toInt(value: number | string) {
|
||||
if (!value) return 0;
|
||||
return toInteger(value);
|
||||
}
|
||||
|
||||
export function toFixedNum(num, digit) {
|
||||
if (!num) return 0;
|
||||
const a = parseFloat(num).toFixed(digit);
|
||||
return a;
|
||||
}
|
||||
//11.返回时间格式
|
||||
export function usTime() {
|
||||
const [YYYY, MM, DD] = timeFormat(new Date(), 'YYYY-MM-DD').split('-');
|
||||
const [hh, mm] = timeFormat(new Date(), 'HH:mm').split(':');
|
||||
return {
|
||||
YYYY,
|
||||
MM,
|
||||
DD,
|
||||
hh,
|
||||
mm,
|
||||
};
|
||||
}
|
||||
|
||||
// 12生成周的区间
|
||||
export function weekRange() {
|
||||
let n = 200;
|
||||
const [start, end] = getMondayDate();
|
||||
const arr = [{ start, end, value: `${start}至${end}`, text: `${start}至${end}` }];
|
||||
while (n > 0) {
|
||||
const t = arr[arr.length - 1].start;
|
||||
const [s, e] = getChooseWeek(new Date(t).getTime() - weekTime);
|
||||
arr.push({ start: s, end: e, value: `${s}至${e}`, text: `${s}至${e}` });
|
||||
n--;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
Reference in New Issue
Block a user