移动端V1.0
This commit is contained in:
57
utils/ai.js
Normal file
57
utils/ai.js
Normal file
@@ -0,0 +1,57 @@
|
||||
export const initCoze = async function(userInfo) {
|
||||
return new CozeWebSDK.WebChatClient({
|
||||
config: {
|
||||
bot_id: '7517200991494717475',
|
||||
botInfo: {
|
||||
parameters: {
|
||||
user_role: userInfo.roleGroup,
|
||||
user_name: userInfo.nickName,
|
||||
user_id: userInfo.username,
|
||||
user_token: userInfo.user_token,
|
||||
}
|
||||
}
|
||||
},
|
||||
auth: {
|
||||
type: "token",
|
||||
token: userInfo.accessToken,
|
||||
onRefreshToken: async () => {
|
||||
return userInfo.userInfo.accessToken;
|
||||
},
|
||||
},
|
||||
userInfo: {
|
||||
id: userInfo.username,
|
||||
nickname: userInfo.nickName,
|
||||
url: userInfo.avater
|
||||
},
|
||||
ui: {
|
||||
base: {
|
||||
icon: "https://p3-flow-imagex-sign.byteimg.com/ocean-cloud-tos/FileBizType.BIZ_BOT_ICON/4185184193750220_1751011524142392616_RI5wYOximW.jpg~tplv-a9rns2rl98-image-qvalue.jpeg?rk3s=bbd3e7ed&x-expires=1753606533&x-signature=OxWu7ZE9AsolGXHOZGxYQf36bt4%3D",
|
||||
layout: "mobile",
|
||||
lang: "zh-CN",
|
||||
zIndex: 1000,
|
||||
},
|
||||
chatBot: {
|
||||
title: "“智水”AI辅导员",
|
||||
uploadable: true,
|
||||
el: document.getElementById("chatbot"),
|
||||
},
|
||||
asstBtn: {
|
||||
isNeed: false
|
||||
},
|
||||
header: {
|
||||
isShow: true,
|
||||
isNeedClose: true,
|
||||
},
|
||||
footer: {
|
||||
isShow: false,
|
||||
expressionText: '智能体由 {{name}}提供技术支持',
|
||||
linkvars: {
|
||||
name: {
|
||||
text: '广西厚溥',
|
||||
link: 'http://www.gxxdit.com/'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
13
utils/auth.js
Normal file
13
utils/auth.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const TokenKey = 'App-Token'
|
||||
|
||||
export function getToken() {
|
||||
return uni.getStorageSync(TokenKey)
|
||||
}
|
||||
|
||||
export function setToken(token) {
|
||||
return uni.setStorageSync(TokenKey, token)
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
return uni.removeStorageSync(TokenKey)
|
||||
}
|
30
utils/checkPic.js
Normal file
30
utils/checkPic.js
Normal file
@@ -0,0 +1,30 @@
|
||||
export function checkPic(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 获取图片的后缀名
|
||||
const suffix = file.name.split('.').pop().toLowerCase();
|
||||
const allowedTypes = ['jpg', 'png', 'jpeg'];
|
||||
const maxSize = 5242880; // 5MB in bytes
|
||||
// 判断后缀是否符合要求
|
||||
if (!allowedTypes.includes(suffix)) {
|
||||
uni.showToast({
|
||||
title: "不支持" + suffix + "格式的图片",
|
||||
icon: "none"
|
||||
});
|
||||
resolve(false);
|
||||
} else if (file.size > maxSize) {
|
||||
uni.showToast({
|
||||
title: "最大只能上传5MB的图片",
|
||||
icon: "none"
|
||||
});
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function isImageUrl(url) {
|
||||
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
|
||||
const extension = url.split('.').pop().toLowerCase();
|
||||
return imageExtensions.includes(extension);
|
||||
}
|
54
utils/common.js
Normal file
54
utils/common.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 显示消息提示框
|
||||
* @param content 提示的标题
|
||||
*/
|
||||
export function toast(content) {
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: content
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示模态弹窗
|
||||
* @param content 提示的标题
|
||||
*/
|
||||
export function showConfirm(content) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: content,
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
success: function(res) {
|
||||
resolve(res)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数处理
|
||||
* @param params 参数
|
||||
*/
|
||||
export function tansParams(params) {
|
||||
let result = ''
|
||||
for (const propName of Object.keys(params)) {
|
||||
const value = params[propName]
|
||||
var part = encodeURIComponent(propName) + "="
|
||||
if (value !== null && value !== "" && typeof (value) !== "undefined") {
|
||||
if (typeof value === 'object') {
|
||||
for (const key of Object.keys(value)) {
|
||||
if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
|
||||
let params = propName + '[' + key + ']'
|
||||
var subPart = encodeURIComponent(params) + "="
|
||||
result += subPart + encodeURIComponent(value[key]) + "&"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result += part + encodeURIComponent(value) + "&"
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
8
utils/constant.js
Normal file
8
utils/constant.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const constant = {
|
||||
avatar: 'vuex_avatar',
|
||||
name: 'vuex_name',
|
||||
roles: 'vuex_roles',
|
||||
permissions: 'vuex_permissions'
|
||||
}
|
||||
|
||||
export default constant
|
11
utils/dict.js
Normal file
11
utils/dict.js
Normal file
@@ -0,0 +1,11 @@
|
||||
export function getDiseaseTypeByDictValue(dictType, dictValue, data) {
|
||||
// 过滤出特定类型的字典数据
|
||||
const filteredData = data.filter(item => item.dictType === dictType);
|
||||
// 在过滤后的数据中查找匹配的dictValue
|
||||
for (const item of filteredData) {
|
||||
if (item.dictValue === dictValue) {
|
||||
return item.dictLabel;
|
||||
}
|
||||
}
|
||||
return '未知';
|
||||
}
|
6
utils/errorCode.js
Normal file
6
utils/errorCode.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
'401': '认证失败,无法访问系统资源',
|
||||
'403': '当前操作没有权限',
|
||||
'404': '访问资源不存在',
|
||||
'default': '系统未知错误,请反馈给管理员'
|
||||
}
|
40
utils/getCurrentDateTime.js
Normal file
40
utils/getCurrentDateTime.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// 封装获取当前时间年月日的函数
|
||||
export function getCurrentDateTime(format = 'yyyy-MM-dd') {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // getMonth() 返回的月份是从 0 开始的
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
|
||||
// 根据传入的 format 返回不同的时间格式
|
||||
switch (format) {
|
||||
case 'yyyy':
|
||||
return year;
|
||||
case 'MM':
|
||||
return month;
|
||||
case 'dd':
|
||||
return day;
|
||||
default:
|
||||
// 默认返回 'yyyy-MM-dd' 格式
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
}
|
||||
export function getCurrentTime(format = 'yyyy-MM-dd HH:mm:ss') {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
|
||||
// 根据传入的 format 字符串拼接日期时间
|
||||
let formattedDateTime = format
|
||||
.replace('yyyy', year)
|
||||
.replace('MM', month)
|
||||
.replace('dd', day)
|
||||
.replace('HH', hours)
|
||||
.replace('mm', minutes)
|
||||
.replace('ss', seconds);
|
||||
|
||||
return formattedDateTime;
|
||||
}
|
16
utils/limitInput.js
Normal file
16
utils/limitInput.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export function limitInput(value,max) {
|
||||
if (value > max) {
|
||||
uni.showToast({
|
||||
title: "只能输入0~" + max + "的数值",
|
||||
icon: "none"
|
||||
})
|
||||
return max;
|
||||
} else if (value < 0) {
|
||||
uni.showToast({
|
||||
title: "只能输入0~" + max + "的数值",
|
||||
icon: "none"
|
||||
})
|
||||
return 0;
|
||||
}
|
||||
return value;
|
||||
}
|
51
utils/permission.js
Normal file
51
utils/permission.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import store from '@/store'
|
||||
|
||||
/**
|
||||
* 字符权限校验
|
||||
* @param {Array} value 校验值
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
export function checkPermi(value) {
|
||||
if (value && value instanceof Array && value.length > 0) {
|
||||
const permissions = store.getters && store.getters.permissions
|
||||
const permissionDatas = value
|
||||
const all_permission = "*:*:*"
|
||||
|
||||
const hasPermission = permissions.some(permission => {
|
||||
return all_permission === permission || permissionDatas.includes(permission)
|
||||
})
|
||||
|
||||
if (!hasPermission) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色权限校验
|
||||
* @param {Array} value 校验值
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
export function checkRole(value) {
|
||||
if (value && value instanceof Array && value.length > 0) {
|
||||
const roles = store.getters && store.getters.roles
|
||||
const permissionRoles = value
|
||||
const super_admin = "admin"
|
||||
|
||||
const hasRole = roles.some(role => {
|
||||
return super_admin === role || permissionRoles.includes(role)
|
||||
})
|
||||
|
||||
if (!hasRole) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
console.error(`need roles! Like checkRole="['admin','editor']"`)
|
||||
return false
|
||||
}
|
||||
}
|
73
utils/request.js
Normal file
73
utils/request.js
Normal file
@@ -0,0 +1,73 @@
|
||||
import store from '@/store'
|
||||
import config from '@/config'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import errorCode from '@/utils/errorCode'
|
||||
import { toast, showConfirm, tansParams } from '@/utils/common'
|
||||
|
||||
let timeout = 10000
|
||||
const baseUrl = config.baseUrl
|
||||
|
||||
const request = config => {
|
||||
// 是否需要设置 token
|
||||
const isToken = (config.headers || {}).isToken === false
|
||||
config.header = config.header || {}
|
||||
if (getToken() && !isToken) {
|
||||
config.header['Authorization'] = 'Bearer ' + getToken()
|
||||
}
|
||||
// get请求映射params参数
|
||||
if (config.params) {
|
||||
let url = config.url + '?' + tansParams(config.params)
|
||||
url = url.slice(0, -1)
|
||||
config.url = url
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
method: config.method || 'get',
|
||||
timeout: config.timeout || timeout,
|
||||
url: config.baseUrl || baseUrl + config.url,
|
||||
data: config.data,
|
||||
header: config.header,
|
||||
dataType: 'json'
|
||||
}).then(response => {
|
||||
let [error, res] = response
|
||||
if (error) {
|
||||
toast('后端接口连接异常')
|
||||
reject('后端接口连接异常')
|
||||
return
|
||||
}
|
||||
const code = res.data.code || 200
|
||||
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
||||
if (code === 401) {
|
||||
showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
|
||||
if (res.confirm) {
|
||||
store.dispatch('LogOut').then(res => {
|
||||
uni.reLaunch({ url: '/pages/login' })
|
||||
})
|
||||
}
|
||||
})
|
||||
reject('无效的会话,或者会话已过期,请重新登录。')
|
||||
} else if (code === 500) {
|
||||
toast(msg)
|
||||
reject('500')
|
||||
} else if (code !== 200) {
|
||||
toast(msg)
|
||||
reject(code)
|
||||
}
|
||||
resolve(res.data)
|
||||
})
|
||||
.catch(error => {
|
||||
let { message } = error
|
||||
if (message === 'Network Error') {
|
||||
message = '后端接口连接异常'
|
||||
} else if (message.includes('timeout')) {
|
||||
message = '系统接口请求超时'
|
||||
} else if (message.includes('Request failed with status code')) {
|
||||
message = '系统接口' + message.substr(message.length - 3) + '异常'
|
||||
}
|
||||
toast(message)
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default request
|
32
utils/storage.js
Normal file
32
utils/storage.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import constant from './constant'
|
||||
|
||||
// 存储变量名
|
||||
let storageKey = 'storage_data'
|
||||
|
||||
// 存储节点变量名
|
||||
let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions]
|
||||
|
||||
const storage = {
|
||||
set: function(key, value) {
|
||||
if (storageNodeKeys.indexOf(key) != -1) {
|
||||
let tmp = uni.getStorageSync(storageKey)
|
||||
tmp = tmp ? tmp : {}
|
||||
tmp[key] = value
|
||||
uni.setStorageSync(storageKey, tmp)
|
||||
}
|
||||
},
|
||||
get: function(key) {
|
||||
let storageData = uni.getStorageSync(storageKey) || {}
|
||||
return storageData[key] || ""
|
||||
},
|
||||
remove: function(key) {
|
||||
let storageData = uni.getStorageSync(storageKey) || {}
|
||||
delete storageData[key]
|
||||
uni.setStorageSync(storageKey, storageData)
|
||||
},
|
||||
clean: function() {
|
||||
uni.removeStorageSync(storageKey)
|
||||
}
|
||||
}
|
||||
|
||||
export default storage
|
37
utils/time-calculation.js
Normal file
37
utils/time-calculation.js
Normal file
@@ -0,0 +1,37 @@
|
||||
export function calculateDays(startDate, endDate) {
|
||||
// 计算时间差,单位为毫秒
|
||||
const timeDiff = endDate - startDate;
|
||||
|
||||
// 将时间差转换为小时
|
||||
const hoursDiff = timeDiff / (1000 * 60 * 60);
|
||||
|
||||
// 根据不同的时间差范围计算天数
|
||||
let days = 0;
|
||||
|
||||
if (hoursDiff >= 8) {
|
||||
// 大于等于8个小时算1天
|
||||
days = Math.ceil(hoursDiff / 24);
|
||||
} else if (hoursDiff >= 4) {
|
||||
// 大于等于4个小时算半天
|
||||
days = 0.5;
|
||||
} else if (hoursDiff >= 2) {
|
||||
// 大于等于2个小时算0.25天
|
||||
days = 0.25;
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
// 判断值是否为时间戳格式并进行转换
|
||||
export function convertToTimestamp(value) {
|
||||
// 如果值已经是时间戳格式,则直接返回
|
||||
if (typeof value === 'number' && !isNaN(value) && isFinite(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// 尝试将值转换为时间戳格式
|
||||
const timestamp = Date.parse(value);
|
||||
|
||||
// 如果转换成功,则返回时间戳;否则返回 NaN
|
||||
return isNaN(timestamp) ? NaN : timestamp;
|
||||
}
|
13
utils/toBack.js
Normal file
13
utils/toBack.js
Normal file
@@ -0,0 +1,13 @@
|
||||
export function toBackPage(delay = 1000, onSuccess = () => {}) {
|
||||
setTimeout(() => {
|
||||
uni.navigateBack({
|
||||
success: () => {
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
const prevPage = pages[pages.length - 2];
|
||||
onSuccess(prevPage);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, delay);
|
||||
}
|
70
utils/upload.js
Normal file
70
utils/upload.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import store from '@/store'
|
||||
import config from '@/config'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import errorCode from '@/utils/errorCode'
|
||||
import { toast, showConfirm, tansParams } from '@/utils/common'
|
||||
|
||||
let timeout = 10000
|
||||
const baseUrl = config.baseUrl
|
||||
|
||||
const upload = config => {
|
||||
// 是否需要设置 token
|
||||
const isToken = (config.headers || {}).isToken === false
|
||||
config.header = config.header || {}
|
||||
if (getToken() && !isToken) {
|
||||
config.header['Authorization'] = 'Bearer ' + getToken()
|
||||
}
|
||||
// get请求映射params参数
|
||||
if (config.params) {
|
||||
let url = config.url + '?' + tansParams(config.params)
|
||||
url = url.slice(0, -1)
|
||||
config.url = url
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
timeout: config.timeout || timeout,
|
||||
url: baseUrl + config.url,
|
||||
filePath: config.filePath,
|
||||
name: config.name || 'file',
|
||||
header: config.header,
|
||||
formData: config.formData,
|
||||
success: (res) => {
|
||||
let result = JSON.parse(res.data)
|
||||
const code = result.code || 200
|
||||
const msg = errorCode[code] || result.msg || errorCode['default']
|
||||
if (code === 200) {
|
||||
resolve(result)
|
||||
} else if (code == 401) {
|
||||
showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => {
|
||||
if (res.confirm) {
|
||||
store.dispatch('LogOut').then(res => {
|
||||
uni.reLaunch({ url: '/pages/login/login' })
|
||||
})
|
||||
}
|
||||
})
|
||||
reject('无效的会话,或者会话已过期,请重新登录。')
|
||||
} else if (code === 500) {
|
||||
toast(msg)
|
||||
reject('500')
|
||||
} else if (code !== 200) {
|
||||
toast(msg)
|
||||
reject(code)
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
let { message } = error
|
||||
if (message == 'Network Error') {
|
||||
message = '后端接口连接异常'
|
||||
} else if (message.includes('timeout')) {
|
||||
message = '系统接口请求超时'
|
||||
} else if (message.includes('Request failed with status code')) {
|
||||
message = '系统接口' + message.substr(message.length - 3) + '异常'
|
||||
}
|
||||
toast(message)
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default upload
|
52
utils/uploadImg.js
Normal file
52
utils/uploadImg.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import uploadFile from "@/plugins/upload.js";
|
||||
import {
|
||||
checkPic
|
||||
} from "@/utils/checkPic.js"
|
||||
|
||||
export function uploadImg(uploadUrl, photo, tempImgs, baseUrl, callback) {
|
||||
uni.chooseImage({
|
||||
count: 3,
|
||||
success: async (img) => {
|
||||
let bool = await checkPic(img.tempFiles[0]);
|
||||
if (bool) {
|
||||
uploadFile(uploadUrl, img.tempFilePaths[0]).then((res) => {
|
||||
let fileName = JSON.parse(res).fileName;
|
||||
if (photo) {
|
||||
photo += "," + fileName
|
||||
} else {
|
||||
photo = fileName
|
||||
}
|
||||
tempImgs.push({
|
||||
path: baseUrl + fileName
|
||||
});
|
||||
// 调用回调函数
|
||||
callback && callback(null, {
|
||||
photo,
|
||||
tempImgs
|
||||
});
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: (error) => {}
|
||||
});
|
||||
}
|
||||
|
||||
export function previewImg(imgs,index=0) {
|
||||
let urls = [];
|
||||
urls = imgs.map(img => img.path);
|
||||
uni.previewImage({
|
||||
urls: urls,
|
||||
current:index
|
||||
})
|
||||
}
|
||||
export function removeImg(index,path,photo,tempImgs,baseUrl,callback) {
|
||||
tempImgs.splice(index, 1);
|
||||
let newImgs = tempImgs.filter(fileName => fileName.path !== path);
|
||||
newImgs = newImgs.map(img => img.path.replace(baseUrl, ''))
|
||||
newImgs = newImgs.join(",");
|
||||
photo = newImgs;
|
||||
// 调用回调函数
|
||||
callback && callback(null, {
|
||||
photo
|
||||
});
|
||||
}
|
12
utils/validateForm.js
Normal file
12
utils/validateForm.js
Normal file
@@ -0,0 +1,12 @@
|
||||
export function validateFormFields(requiredFields, formData) {
|
||||
const emptyField = requiredFields.find(field => formData[field] === "");
|
||||
// 如果找到空字段,则显示提示并返回
|
||||
if (emptyField) {
|
||||
uni.showToast({
|
||||
title: `必填 * 字段不能为空`, // 可选:显示具体哪个字段为空
|
||||
icon: "none"
|
||||
});
|
||||
return false; // 返回false表示验证失败
|
||||
}
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user