mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-06 09:26:45 +08:00
2022年5月29日 从svn移到git
This commit is contained in:
31
utils/index.js
Normal file
31
utils/index.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 表格时间格式化
|
||||
*/
|
||||
export function formatDate(cellValue) {
|
||||
if (cellValue == null || cellValue == "") return "";
|
||||
var date = new Date(cellValue)
|
||||
var year = date.getFullYear()
|
||||
var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
||||
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||
var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
|
||||
var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
|
||||
var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
|
||||
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
|
||||
}
|
||||
// 秒转时分秒
|
||||
export function formatSeconds(value) {
|
||||
let result = parseInt(value)
|
||||
let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
|
||||
let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
|
||||
let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
|
||||
|
||||
let res = '';
|
||||
if(h !== '00'){
|
||||
res += `${h}小时`;
|
||||
}
|
||||
if(m !== '00' || h !== '00'){
|
||||
res += `${m}分`;
|
||||
}
|
||||
res += `${s}秒`;
|
||||
return res;
|
||||
}
|
||||
0
utils/interceptor.js
Normal file
0
utils/interceptor.js
Normal file
73
utils/study.js
Normal file
73
utils/study.js
Normal file
@@ -0,0 +1,73 @@
|
||||
/**用于控制学习情况*/
|
||||
const studyDurationKey='xus_duration';
|
||||
const studyVideoSpeedKey='xus_video_speed';
|
||||
const studyVideoKeyPre='xus_video';
|
||||
|
||||
|
||||
const setVideoSpeed=function(speed){
|
||||
uni.setStorageSync(studyVideoSpeedKey,speed);
|
||||
}
|
||||
|
||||
const getVideoSpeed=function(){
|
||||
let speed=uni.getStorageSync(studyVideoSpeedKey);
|
||||
if(speed){
|
||||
return Number(speed);
|
||||
}else{
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置视频的播放时间
|
||||
* @param {} courseId
|
||||
* @param {*} time
|
||||
*/
|
||||
const setVideoTime=function(courseId,time){
|
||||
uni.setStorageSync(studyVideoKeyPre+'_'+courseId,time);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地存储的学习时长
|
||||
*/
|
||||
const setStudyDuration=function(duration){
|
||||
console.log(duration,'设置时长');
|
||||
uni.setStorageSync(studyDurationKey,duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除本地记录的学习时长
|
||||
*/
|
||||
const clearStudyDuration=function(){
|
||||
uni.setStorageSync(studyDurationKey,0);
|
||||
}
|
||||
|
||||
const getStudyDuration=function(){
|
||||
let speedValue=uni.getStorageSync(studyDurationKey);
|
||||
if(speedValue){
|
||||
//console.log(speedValue,'speedValue');
|
||||
return Number(speedValue);
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 追加学习时长
|
||||
* @param Number duration 学习时长(秒)
|
||||
*/
|
||||
const appendStudyDuration=function(duration){
|
||||
let speedValue=uni.getStorageSync(studyDurationKey);
|
||||
if(speedValue){
|
||||
localStorage.setStorageSync(studyDurationKey,Number(speedValue)+duration);
|
||||
}else{
|
||||
localStorage.setStorageSync(studyDurationKey,duration);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
setVideoSpeed,
|
||||
getVideoSpeed,
|
||||
getStudyDuration,
|
||||
setStudyDuration,
|
||||
clearStudyDuration,
|
||||
appendStudyDuration
|
||||
}
|
||||
33
utils/token.js
Normal file
33
utils/token.js
Normal file
@@ -0,0 +1,33 @@
|
||||
//const TOKEN_KEY = 'XBOE-Access-Token'
|
||||
const TOKEN_KEY = 'token'
|
||||
|
||||
export function getToken() {
|
||||
let token=uni.getStorageSync(TOKEN_KEY);
|
||||
if(!token){
|
||||
token=uni.getStorageSync('userInfo');
|
||||
if(token){
|
||||
token=JSON.parse(token).token;
|
||||
}
|
||||
}
|
||||
return token;
|
||||
//return uni.getStorageSync(TOKEN_KEY);
|
||||
}
|
||||
|
||||
export function setToken(token) {
|
||||
return uni.setStorageSync(TOKEN_KEY,token);
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
uni.removeStorageSync(TOKEN_KEY);
|
||||
uni.removeStorageSync('returnUrl');
|
||||
uni.setStorageSync('oh','quit');
|
||||
uni.removeStorageSync('userInfo');
|
||||
uni.removeStorageSync('inner');
|
||||
// #ifdef H5
|
||||
document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
||||
document.cookie = "userInfo=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
||||
document.cookie = "inner=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
||||
// #endif
|
||||
}
|
||||
|
||||
export const tokenName='token';
|
||||
202
utils/tools.js
Normal file
202
utils/tools.js
Normal file
@@ -0,0 +1,202 @@
|
||||
// 类型过滤
|
||||
const contentTypeMaps = {
|
||||
10: '视频',
|
||||
20: '音频',
|
||||
30: '图片',
|
||||
40: '文档',
|
||||
41: '图文',
|
||||
50: 'scrom包',
|
||||
52: '外部连接',
|
||||
60: '作业',
|
||||
61: '考试',
|
||||
62: '评估',
|
||||
90: '其它',
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取课程内容的类型名称
|
||||
* @param {Object} type
|
||||
*/
|
||||
export function getContentType(type) {
|
||||
let name = contentTypeMaps[type];
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取课程类型的名称 10微课,21在线课(直播);20:在线课( 录播);30:面授课;40:混合式,
|
||||
* @param {Object} type
|
||||
*/
|
||||
export function getCourseType(type) {
|
||||
const maps = {
|
||||
10: '录播课',
|
||||
21: '直播课',
|
||||
20: '录播课',
|
||||
30: '面授课',
|
||||
40: '混合式',
|
||||
};
|
||||
return maps[type];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取url协议
|
||||
* @param {Object} type
|
||||
*/
|
||||
export function getUrlPre(type) {
|
||||
const isHttps = 'https:' == document.location.prototype ? true : false;
|
||||
let isUrl = 'https';
|
||||
if (isHttps) {
|
||||
isUrl = 'https';
|
||||
} else {
|
||||
isUrl = 'http';
|
||||
}
|
||||
return isUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期,转化为 yyyy-MM-dd HH:mm:ss 格式
|
||||
* @param {Object} date
|
||||
*/
|
||||
export function formatDate(date) {
|
||||
if (date == null || date == '') {
|
||||
return;
|
||||
}
|
||||
var year = new Date(Number(date)).getFullYear(),
|
||||
month = new Date(Number(date)).getMonth() + 1, //月份是从0开始的
|
||||
day = new Date(Number(date)).getDate(),
|
||||
hour = new Date(Number(date)).getHours(),
|
||||
min = new Date(Number(date)).getMinutes(),
|
||||
sec = new Date(Number(date)).getSeconds();
|
||||
if (month < 10) {
|
||||
month = '0' + month
|
||||
}
|
||||
if (day < 10) {
|
||||
day = '0' + day
|
||||
}
|
||||
if (hour < 10) {
|
||||
hour = '0' + hour
|
||||
}
|
||||
if (min < 10) {
|
||||
min = '0' + min
|
||||
}
|
||||
if (sec < 10) {
|
||||
sec = '0' + sec
|
||||
}
|
||||
var newTime = year + '-' +
|
||||
month + '-' +
|
||||
day + ' ' +
|
||||
hour + ':' +
|
||||
min + ':' +
|
||||
sec;
|
||||
return newTime;
|
||||
|
||||
}
|
||||
|
||||
export function toScore(score) {
|
||||
if (!score || score == 0) {
|
||||
return '未评';
|
||||
}
|
||||
if (('' + score).indexOf('.') > -1) {
|
||||
return score.toFixed(1);
|
||||
} else {
|
||||
return score + '.0';
|
||||
}
|
||||
}
|
||||
export function toScoreTow(score) { // 返回两位小数
|
||||
if (!score) {
|
||||
return '0';
|
||||
}
|
||||
if (('' + score).indexOf('.') > -1) {
|
||||
return score.toFixed(2);
|
||||
} else {
|
||||
return score + '.00';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字转化为字母
|
||||
* @param {Object} x
|
||||
*/
|
||||
export function numberToLetter(x) {
|
||||
let s = "";
|
||||
while (x > 0) {
|
||||
let m = x % 26;
|
||||
m = m === 0 ? (m = 26) : m;
|
||||
s = String.fromCharCode(96 + parseInt(m)) + s;
|
||||
x = (x - m) / 26;
|
||||
}
|
||||
return s.toUpperCase();
|
||||
}
|
||||
|
||||
export function getQuestionType(type) {
|
||||
let name = '';
|
||||
switch (type) {
|
||||
case 101:
|
||||
name = '单选';
|
||||
break;
|
||||
case 102:
|
||||
name = '多选';
|
||||
break;
|
||||
case 103:
|
||||
name = '判断';
|
||||
break;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
export function examType(type) {
|
||||
let name = '';
|
||||
switch (type) {
|
||||
case 1:
|
||||
name = '单选';
|
||||
break;
|
||||
case 2:
|
||||
name = '多选';
|
||||
break;
|
||||
case 3:
|
||||
name = '判断';
|
||||
break;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* 上方法没有说明
|
||||
* @param {Object} ditem
|
||||
*/
|
||||
export function correctJudgment(ditem) {
|
||||
let judgment = false;
|
||||
if (ditem.type == 101 || ditem.type == 103) {
|
||||
ditem.options.forEach(item => {
|
||||
if (item.answer) {
|
||||
if (item.id == ditem.userAnswer) {
|
||||
judgment = true;
|
||||
} else {
|
||||
judgment = false;
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
ditem.options.forEach(item => {
|
||||
if (item.answer == item.isCheck) {
|
||||
judgment = true;
|
||||
|
||||
} else {
|
||||
judgment = false;
|
||||
}
|
||||
})
|
||||
}
|
||||
return judgment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 头像文字
|
||||
* @param {*} text
|
||||
* @returns
|
||||
*/
|
||||
export function userAvatarText(text) {
|
||||
if (text) {
|
||||
let len = text.length;
|
||||
if (len > 2) {
|
||||
text = text.substring(len - 2);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
86
utils/upload.js
Normal file
86
utils/upload.js
Normal file
@@ -0,0 +1,86 @@
|
||||
import config from '@/config/index.js'
|
||||
import {getToken} from '@/utils/token.js'
|
||||
|
||||
function chooseImg(count, success) {
|
||||
//console.log(count)
|
||||
uni.chooseImage({
|
||||
count: count,
|
||||
sizeType: ['compressed'],
|
||||
success: res => {
|
||||
// console.log(res)
|
||||
// console.log(res.tempFilePaths)
|
||||
uploadFiles(res.tempFilePaths,success)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function uploadFiles(paths,success) {
|
||||
uni.showLoading({
|
||||
title: '正在上传'
|
||||
})
|
||||
for (let path of paths) {
|
||||
try {
|
||||
const uploadData = await uploadFile(path)
|
||||
//console.log(uploadData)
|
||||
success(uploadData)
|
||||
} catch(err) {
|
||||
//console.log(err)
|
||||
uni.showToast({
|
||||
title:err||'上传失败',
|
||||
icon:'error',
|
||||
mask:true
|
||||
})
|
||||
break;
|
||||
}
|
||||
}
|
||||
uni.hideLoading()
|
||||
}
|
||||
|
||||
/**
|
||||
* 只支持通过chooseImg选择返回的path
|
||||
* @param {Object} path
|
||||
* @param {Object} data
|
||||
*/
|
||||
function uploadFile(path,data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let a = uni.uploadFile({
|
||||
header: {
|
||||
'XBOE-Access-Token': getToken()
|
||||
},
|
||||
url: config.apiBaseUrl+'/xboe/sys/xuploader/file/upload', // 仅为示例,非真实的接口地址
|
||||
filePath: path,
|
||||
name: 'file',
|
||||
formData: data,
|
||||
success: (res) => {
|
||||
resolve(JSON.parse(res.data));
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过文件对象上传
|
||||
* @param {Object} file
|
||||
* @param {Object} data
|
||||
*/
|
||||
function uploadFileObject(file,data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let a = uni.uploadFile({
|
||||
header: {
|
||||
'XBOE-Access-Token': getToken()
|
||||
},
|
||||
url: config.apiBaseUrl+'/xboe/sys/xuploader/file/upload', // 仅为示例,非真实的接口地址
|
||||
file: file,
|
||||
name: 'file',
|
||||
formData: data,
|
||||
success: (res) => {
|
||||
resolve(JSON.parse(res.data));
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
uploadFile,
|
||||
uploadFileObject
|
||||
}
|
||||
165
utils/xajax.js
Normal file
165
utils/xajax.js
Normal file
@@ -0,0 +1,165 @@
|
||||
import config from '../config/index.js'
|
||||
import {getToken} from '@/utils/token.js'
|
||||
import qs from 'qs'
|
||||
|
||||
const ReLoginUrl="/login";
|
||||
|
||||
const formatUrl=function(url){
|
||||
if(url.startsWith('http') || url.startsWith('https')){
|
||||
//console.log(url,"我拿到的url值,我想知道下面有啥方法")
|
||||
return url;
|
||||
}else{
|
||||
return config.apiBaseUrl+url
|
||||
}
|
||||
}
|
||||
const formRequest=function(method,url,data){
|
||||
let token=getToken();
|
||||
if(!token){
|
||||
token='';
|
||||
}
|
||||
let headers={
|
||||
'content-type':'application/x-www-form-urlencoded',
|
||||
'XBOE-Access-Token':token
|
||||
}
|
||||
let reUrl=formatUrl(url);
|
||||
return new Promise(function(resolve, reject){
|
||||
uni.request({
|
||||
url: reUrl,
|
||||
method,
|
||||
data: data,
|
||||
xhrFields: {withCredentials: true},
|
||||
dataType: 'json',
|
||||
header: headers,
|
||||
success:function(rs,statusCode){
|
||||
if(rs.statusCode==200){
|
||||
if(rs.data.status==401 || rs.data.status==402){
|
||||
let loginPath=config.loginPath;
|
||||
if(loginPath.startsWith('http')){
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
//window.open(loginPath)
|
||||
location.href=loginPath
|
||||
// #endif
|
||||
}else{
|
||||
uni.redirectTo({
|
||||
url:loginPath
|
||||
})
|
||||
}
|
||||
}else{
|
||||
resolve(rs.data);
|
||||
}
|
||||
}else{
|
||||
reject("API请求错误");
|
||||
}
|
||||
},
|
||||
fail:function(err){
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
const jsonRequest=function(method,url,data){
|
||||
let token=getToken();
|
||||
if(!token){
|
||||
token='';
|
||||
}
|
||||
let headers={
|
||||
'XBOE-Access-Token':token
|
||||
}
|
||||
let reUrl=formatUrl(url);
|
||||
return new Promise(function(resolve, reject){
|
||||
|
||||
uni.request({
|
||||
url: reUrl,
|
||||
method,
|
||||
data: data,
|
||||
xhrFields: {withCredentials: true},
|
||||
dataType: 'json',
|
||||
header: headers,
|
||||
success:function(rs,statusCode){
|
||||
if(rs.statusCode==200){
|
||||
if(rs.data.status==401 || rs.data.status==402){
|
||||
let loginPath=config.loginPath;
|
||||
if(loginPath.startsWith('http')){
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
//window.open(loginPath)
|
||||
location.href=loginPath
|
||||
// #endif
|
||||
}else{
|
||||
uni.redirectTo({
|
||||
url:loginPath
|
||||
})
|
||||
}
|
||||
}else{
|
||||
resolve(rs.data);
|
||||
}
|
||||
}else{
|
||||
reject("API请求错误");
|
||||
}
|
||||
},
|
||||
fail:function(err){
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
//get请求
|
||||
const get=function(url){
|
||||
return formRequest('GET',url,'');
|
||||
}
|
||||
//post请求
|
||||
const post=function(url,data){
|
||||
if(data){
|
||||
data=qs.stringify(data);
|
||||
}
|
||||
return formRequest('POST',url,data);
|
||||
}
|
||||
//postJson请求
|
||||
const postJson=function(url,json){
|
||||
return jsonRequest('POST',url,json);
|
||||
}
|
||||
//put请求
|
||||
const put=function(url,data){
|
||||
if(data){
|
||||
data=qs.stringify(data);
|
||||
}
|
||||
return formRequest('PUT',url,data);
|
||||
}
|
||||
//putJson请求
|
||||
const putJson=function(url,json){
|
||||
return jsonRequest('PUT',url,json);
|
||||
}
|
||||
//patch请求
|
||||
const patch=function(url,data){
|
||||
if(data){
|
||||
data=qs.stringify(data);
|
||||
}
|
||||
return formRequest('PATCH',url,data);
|
||||
}
|
||||
//patchJson请求
|
||||
const patchJson=function(url,json){
|
||||
return jsonRequest('PATCH',url,json);
|
||||
}
|
||||
//delete请求
|
||||
const del=function(url,data){
|
||||
if(data){
|
||||
data=qs.stringify(data);
|
||||
}
|
||||
return formRequest('DELETE',url,data);
|
||||
}
|
||||
export default {
|
||||
get,
|
||||
post,
|
||||
postJson,
|
||||
put,
|
||||
putJson,
|
||||
patch,
|
||||
patchJson,
|
||||
del
|
||||
}
|
||||
Reference in New Issue
Block a user