123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561 |
- import {
- baseUrl,
- baseApiUrl
- } from './config.js';
- import * as common from './common.js' //引入common
- import * as db from './db.js' //引入common
- // 需要登陆的,都写到这里,否则就是不需要登陆的接口
- let methodsToken = ['profile', 'refreshUser', 'wxLogin', 'changeMobile', 'addCart',
- 'previewOrder', 'getWuyuanUser', 'archives_post', 'get_channel_fields', 'get_channel', 'lists', 'details',
- 'logOffVolunteer', 'getCrProperty', 'joinTeam', 'getTeamMember', 'getPatrolTask', 'claimCr',
- 'getPatrolLog', 'claimCrList', 'claimCrDetails', 'editMainBodyUser', , 'contribute',
- 'getPatrolTaskDetails', 'getContentDetail', 'examineVolunteer', 'userManageRegionCrAuth', 'applyVolunteer',
- 'getPhoneNumber', 'editApplyVolunteer', 'mobileBindVolunteer', 'getTeamDetails', 'examineTask', 'removeMemberm',
- 'getScoreLog', 'rankingList', 'getMainBodyColumnContentList', 'regionData', 'cityData', 'checkIn',
- 'getMainBodyUser', 'getUserContribute', 'getUserHonor', 'submitTask', 'exportPatrolRecord'
- ];
- const post = (method, data, callback, type, orgurl) => {
- let userToken = '';
- let auth = '';
- // 判断token是否存在
- console.log("method: ", method);
- if (methodsToken.indexOf(method) >= 0) {
- // 获取用户token
- let auth = db.get("auth");
- // console.log(auth);
- let nowdate = (new Date()) / 1000; //当前时间戳
- //新增用户判断是否登录逻辑begin
- common.isLogin();
- //新增用户判断是否登录逻辑end
- if (!auth || auth.createtime + auth.expires_in < nowdate) {
- common.toLogin();
- return false;
- } else {
- userToken = auth.token;
- }
- }
- if (type) {
- method = type + '/' + method
- } else {
- method = '/' + method
- }
- let realurl = baseApiUrl + method;
- if (orgurl) {
- realurl = baseUrl + orgurl;
- }
- uni.showLoading({
- title: '',
- icon: 'loading'
- });
- uni.request({
- url: realurl,
- data: data,
- header: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'token': userToken,
- '__token__': userToken
- },
- method: 'POST',
- success: (response) => {
- uni.hideLoading();
- const result = response.data
- if (result.msg == 'Please login' || result.msg == '请登陆') {
- db.del("user");
- db.del("auth");
- console.log('未登陆')
- uni.showToast({
- title: result.msg,
- icon: 'none',
- duration: 2000,
- complete: function() {
- uni.reLaunch({
- url: '/pages/index/index',
- })
- }
- });
- }
- callback(result);
- },
- fail: (error) => {
- uni.hideLoading();
- if (error && error.response) {
- showError(error.response);
- }
- },
- });
- }
- // 上传图片
- export const uploadImage = (method, data = {}, callback, num = 9, type) => {
- if (type) {
- method = type + '/' + method
- } else {
- method = method
- }
- let userToken = '';
- let auth = db.get("auth");
- userToken = auth.token;
- uni.chooseImage({
- count: num,
- success: (res) => {
- uni.showLoading({
- title: '上传中...'
- });
- let tempFilePaths = res.tempFilePaths
- for (var i = 0; i < tempFilePaths.length; i++) {
- data.file = tempFilePaths[i]
- uni.uploadFile({
- url: baseApiUrl + method,
- filePath: tempFilePaths[i],
- fileType: 'image',
- name: 'file',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'multipart/form-data',
- 'token': userToken
- },
- formData: data,
- success: (uploadFileRes) => {
- callback(JSON.parse(uploadFileRes.data))
- },
- fail: (error) => {
- if (error && error.response) {
- common.showError(error.response);
- }
- },
- complete: () => {
- setTimeout(function() {
- uni.hideLoading();
- }, 250);
- },
- });
- }
- }
- });
- }
- const get = (url, callback) => {
- uni.showLoading({
- title: '加载中'
- });
- let realurl = baseUrl + url;
- if (url.indexOf('http:') >= 0 || url.indexOf('https:') >= 0) {
- let realurl = url;
- }
- uni.request({
- url: realurl,
- header: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
- },
- method: 'GET',
- success: (response) => {
- callback(response.data);
- },
- fail: (error) => {
- if (error && error.response) {
- showError(error.response);
- }
- },
- complete: () => {
- setTimeout(function() {
- uni.hideLoading();
- }, 250);
- }
- });
- }
- const showError = error => {
- let errorMsg = ''
- switch (error.status) {
- case 400:
- errorMsg = '请求参数错误'
- break
- case 401:
- errorMsg = '未授权,请登录'
- break
- case 403:
- errorMsg = '跨域拒绝访问'
- break
- case 404:
- errorMsg = `请求地址出错: ${error.config.url}`
- break
- case 408:
- errorMsg = '请求超时'
- break
- case 500:
- errorMsg = '服务器内部错误'
- break
- case 501:
- errorMsg = '服务未实现'
- break
- case 502:
- errorMsg = '网关错误'
- break
- case 503:
- errorMsg = '服务不可用'
- break
- case 504:
- errorMsg = '网关超时'
- break
- case 505:
- errorMsg = 'HTTP版本不受支持'
- break
- default:
- errorMsg = error.msg
- break
- }
- uni.showToast({
- title: errorMsg,
- icon: 'none',
- duration: 2000
- });
- }
- const syncget = (url, data) => {
- return new Promise(function(resolve, reject) {
- get(url + queryParams(data, true), (result) => {
- try {
- resolve(result);
- } catch (e) {
- reject(e);
- }
- })
- })
- }
- const syncpost = (f, m, d) => {
- return new Promise(function(resolve, reject) {
- post(f, d, (result) => {
- try {
- resolve(result);
- } catch (e) {
- reject(e);
- }
- }, m, m);
- })
- }
- // 登录
- export const third = (data, callback) => post('third', data, callback, 'content/main_body_user');
- // 用户绑定手机
- export const bindphone = (data, callback) => post('bind', data, callback, 'discover/User');
- // 修改用户信息
- export const profile = (data, callback) => post('profile', data, callback, 'discover/User');
- // 发送验证码
- export const sendSmsVerify = (data, callback) => post('sendSmsVerify', data, callback, 'discover/User');
- // 刷新用户
- export const refreshUser = (data, callback) => post('refreshUser', data, callback, 'content/main_body_user');
- // 注册
- export const register = (data, callback) => post('register', data, callback, 'discover/User');
- // 登录
- export const login = (data, callback) => post('login', data, callback, 'discover/User');
- // 退出登录
- export const logout = (data, callback) => post('logout', data, callback, 'discover/User');
- // 上传头像
- export const upload = (data, callback) => post('upload', data, callback, 'discover/Ajax');
- // 绑定手机
- export const changeMobile = (data, callback) => post('changeMobile', data, callback, 'discover/User');
- //获取手机号前先登录
- export const wxLogin = (data, callback) => post('wxLogin', data, callback, 'user');
- //获取手机号
- // export const getMobile = (data, callback) => post('getPhoneNumber', data, callback, 'user');
- //取CMS配置
- export const getConfig = async (params = {}) => await syncget('addons/cms/api.common/init', params);
- function queryParams(data = {}, isPrefix = true, arrayFormat = 'brackets') {
- let prefix = isPrefix ? '?' : ''
- let _result = []
- if (['indices', 'brackets', 'repeat', 'comma'].indexOf(arrayFormat) == -1) arrayFormat = 'brackets';
- for (let key in data) {
- let value = data[key]
- // 去掉为空的参数
- if (['', undefined, null].indexOf(value) >= 0) {
- continue;
- }
- if (value.length > 0) {
- value = value.replace(/%/g, "%25");
- value = value.replace(/\&/g, "%26");
- value = value.replace(/\+/g, "%2B");
- }
- // 如果值为数组,另行处理
- if (value.constructor === Array) {
- // e.g. {ids: [1, 2, 3]}
- switch (arrayFormat) {
- case 'indices':
- // 结果: ids[0]=1&ids[1]=2&ids[2]=3
- for (let i = 0; i < value.length; i++) {
- _result.push(key + '[' + i + ']=' + value[i])
- }
- break;
- case 'brackets':
- // 结果: ids[]=1&ids[]=2&ids[]=3
- value.forEach(_value => {
- _result.push(key + '[]=' + _value)
- })
- break;
- case 'repeat':
- // 结果: ids=1&ids=2&ids=3
- value.forEach(_value => {
- _result.push(key + '=' + _value)
- })
- break;
- case 'comma':
- // 结果: ids=1,2,3
- let commaStr = "";
- value.forEach(_value => {
- commaStr += (commaStr ? "," : "") + _value;
- })
- _result.push(key + '=' + commaStr)
- break;
- default:
- value.forEach(_value => {
- _result.push(key + '[]=' + _value)
- })
- }
- } else {
- _result.push(key + '=' + value)
- }
- }
- return _result.length ? prefix + _result.join('&') : ''
- }
- // 模型的主体栏目列表
- export const getColumnList = (data, callback) => post('getColumnList', data, callback,
- 'content/main_body_column');
- // 内容详情
- export const getContentDetail = (data, callback) => post('getContentDetail', data, callback,
- 'content/content');
- // 模型内容列表
- export const getContentList = (data, callback) => post('getContentList', data, callback,
- 'content/content');
- // 模型主体栏目的内容列表
- export const getMainBodyColumnContentList = (data, callback) => post('getMainBodyColumnContentList', data, callback,
- 'content/content');
- // 培训分类列表
- export const getCategoryList = (data, callback) => post('getCategoryList', data, callback, '',
- 'addons/yuneducation/course/getCategoryList');
- // 学院底部课程
- export const getHomeData = (data, callback) => post('getHomeData', data, callback, '',
- 'addons/yuneducation/page/getHomeData');
- // 课程界面数据
- export const getCourseList = (data, callback) => post('getCourseList', data, callback, '',
- 'addons/yuneducation/course/getCourseList');
- // 课程详情
- export const getCourseDetail = (data, callback) => post('getCourseDetail', data, callback, '',
- 'addons/yuneducation/course/getCourseDetail');
- // 获取课程考核
- export const getCourseExamine = (data, callback) => post('getCourseExamine', data, callback, '',
- 'addons/yuneducation/course/getCourseExamine');
- // 课程开始学习
- export const startLearn = (data, callback) => post('startLearn', data, callback, '',
- 'addons/yuneducation/course/startLearn');
- // 加入购物车
- export const addCart = (data, callback) => post('addCart', data, callback, '',
- 'addons/yuneducation/order/addCart');
- // 预览订单
- export const previewOrder = (data, callback) => post('previewOrder', data, callback, '',
- 'addons/yuneducation/order/previewOrder');
- // 提交订单
- export const submitOrder = (data, callback) => post('submitOrder', data, callback, '',
- 'addons/yuneducation/order/submitOrder');
- // 移除购物车
- export const removeCart = (data, callback) => post('removeCart', data, callback, '',
- 'addons/yuneducation/order/removeCart');
- // 讲师详情
- export const getTeacherDetail = (data, callback) => post('getTeacherDetail', data, callback, '',
- 'addons/yuneducation/teacher/getTeacherDetail');
- // 获取培训列表
- export const getScheduleList = (data, callback) => post('getScheduleList', data, callback, '',
- 'addons/yuneducation/schedule/getScheduleList');
- // 获取培训详情
- export const getScheduleDetail = (data, callback) => post('getScheduleDetail', data, callback, '',
- 'addons/yuneducation/schedule/getScheduleDetail');
- // 培训开始学习
- export const scheduleStartLearn = (data, callback) => post('startLearn', data, callback, '',
- 'addons/yuneducation/schedule/startLearn');
- // 获取我的课程列表
- export const getMineCourseList = (data, callback) => post('getMineCourseList', data, callback, '',
- 'addons/yuneducation/course/getMineCourseList');
- // 试播
- // export const getContentDetail = (data, callback) => post('getContentDetail', data, callback, '',
- // 'addons/yuneducation/course/getContentDetail');
- //获取栏目
- export const getChannel = async (params = {}) => await syncpost('get_channel', '/addons/cms/api.archives/get_channel',
- params);
- //我发的文章
- export const myArchives = async (params = {}) => await syncpost('my', '/addons/cms/api.archives/my', params);
- // 文物管理相关
- //场馆详情页获取管理员权限
- export const adminCrAuth = (data, callback) => post('adminCrAuth', data, callback, 'wuyuan/admin');
- //取文巡查记录
- export const getPatrolLog = (data, callback) => post('getPatrolLog', data, callback, 'wuyuan/volunteer');
- //取文物详情
- export const getCulturalDetails = (data, callback) => get('api/wuyuan/cultural_relic/details' + queryParams(data, true),
- callback);
- // 文物管理相关end
- //取轮播图
- export const getBannerList = (data, callback) => get('/api/wuyuan/swiper_icon/lists' + queryParams(data, true),
- callback);
- // //人物列表 传 type参数类型:inheritor=非遗传承人,history=历史人物,folklore=民俗学者,specialist=文史专家
- // export const getPeopleList = (data, callback) => get('api/wuyuan/biographies/lists' + queryParams(data, true), callback);
- // //人物详情
- // export const getPeopleDetails = (data, callback) => get('api/wuyuan/biographies/details' + queryParams(data, true), callback);
- // 获取用户信息
- export const getMainBodyUser = (data, callback) => post('getMainBodyUser', data, callback,
- 'content/main_body_user/getMainBodyUser');
- //修改头像
- export const editMainBodyUser = (data, callback) => post('editMainBodyUser', data, callback,
- 'content/main_body_user');
- //取任务列表
- export const getTaskList = (data, callback) => post('lists', data, callback, 'wuyuan/task');
- //取法律文章列表
- export const getArchives = async (params = {}) => await syncget('https://huli-app.wenlvti.net/addons/cms/api', params);
- // 积分信息
- export const getWuyuanUser = (data, callback) => post('getWuyuanUser', data, callback, 'wuyuan/user');
- //取文物分类 参数传type类型
- export const getCulturalRelicCategory = (data, callback) => get('api/content/category/getCategoryList' + queryParams(
- data,
- true), callback);
- //取级联分类
- export const getCategoryCascadeList = (data, callback) => get('api/content/category/getCategoryCascadeList' +
- queryParams(
- data, true), callback);
- // 投稿
- export const contribute = (data, callback) => post('contribute', data, callback, '',
- 'api/content/style/contribute');
- //取文物场景列表
- export const getCulturalRelic = (data, callback) => get('api/content/cultural_relic/lists' + queryParams(data, true),
- callback);
- // 志愿报名
- export const applyVolunteer = (data, callback) => post('applyVolunteer', data, callback, '',
- 'api/volunteer/volunteer/applyVolunteer');
- // 志愿者列表
- export const lists = (data, callback) => post('lists', data, callback, '', 'api/volunteer/volunteer/lists');
- // 志愿者详情
- export const details = (data, callback) => post('details', data, callback, '', 'api/volunteer/volunteer/details');
- // 注销志愿者
- export const logOffVolunteer = (data, callback) => post('logOffVolunteer', data, callback, '',
- 'api/volunteer/volunteer/logOffVolunteer');
- // 志愿者巡查文物资产列表
- export const getCrProperty = (data, callback) => post('getCrProperty', data, callback, '',
- 'api/volunteer/patrol_property/getCrProperty');
- // 加入志愿者团队
- export const joinTeam = (data, callback) => post('joinTeam', data, callback, '',
- 'api/volunteer/team_member/joinTeam');
- // 获取团队成员列表
- export const getTeamMember = (data, callback) => post('getTeamMember', data, callback, '',
- 'api/volunteer/team/getTeamMember');
- // 移除成员
- export const removeMemberm = (data, callback) => post('removeMemberm', data, callback, '',
- 'api/volunteer/team_member/removeMember');
- // 获取志愿者任务列表
- export const getPatrolTask = (data, callback) => post('getPatrolTask', data, callback, '',
- 'api/volunteer/patrol_task/getPatrolTask');
- // 获取任务列详情
- export const getPatrolTaskDetails = (data, callback) => post('getPatrolTaskDetails', data, callback, '',
- 'api/volunteer/patrol_task/getPatrolTaskDetails');
- // 提交巡查任务
- export const submitTask = (data, callback) => post('submitTask', data, callback, '',
- 'api/volunteer/patrol_task/submitTask');
- // 计算志愿者与文物点的距离
- export const distanceCheck = (data, callback) => post('distanceCheck', data, callback, '',
- 'api/volunteer/patrol_task/distanceCheck');
- // 认领文物
- export const claimCr = (data, callback) => post('claimCr', data, callback, '',
- 'api/volunteer/claim_cr/claimCr');
- // 认领文物列表
- export const claimCrList = (data, callback) => post('claimCrList', data, callback, '',
- 'api/volunteer/claim_cr/claimCrList');
- // 认领文物详情暂未调用
- export const claimCrDetails = (data, callback) => post('claimCrDetails', data, callback, '',
- 'api/volunteer/claim_cr/claimCrDetails');
- // 最新公告
- export const getNotice = (data, callback) => post('getNotice', data, callback, '',
- 'api/system/notice/getNotice');
- // 区域
- export const getCategoryOnlyChildList = (data, callback) => post('getCategoryOnlyChildList', data, callback, '',
- 'api/content/category/getCategoryOnlyChildList');
- // 志愿者审核
- export const examineVolunteer = (data, callback) => post('examineVolunteer', data, callback, '',
- 'api/volunteer/volunteer/examineVolunteer');
- // 用户区域管理文物权限
- export const userManageRegionCrAuth = (data, callback) => post('userManageRegionCrAuth', data, callback, '',
- 'api/auth/user_manage_cr/userManageRegionCrAuth');
- // 修改驳回志愿者信息
- export const editApplyVolunteer = (data, callback) => post('editApplyVolunteer', data, callback, '',
- 'api/volunteer/volunteer/editApplyVolunteer');
- // 老志愿者手机号绑定志愿者
- export const getPhoneNumber = (data, callback) => post('getPhoneNumber', data, callback, '',
- 'api/volunteer/volunteer/getPhoneNumber');
- // 手动绑定志愿者手机号
- export const mobileBindVolunteer = (data, callback) => post('mobileBindVolunteer', data, callback, '',
- 'api/volunteer/volunteer/mobileBindVolunteer');
- // 提交任务审核
- export const examineTask = (data, callback) => post('examineTask', data, callback, '',
- 'api/volunteer/patrol_task/examineTask');
- // 获取用户积分列表
- export const getScoreLog = (data, callback) => post('getScoreLog', data, callback, '',
- 'api/content/main_body_user/getScoreLog');
- // 志愿者排行
- export const rankingList = (data, callback) => post('rankingList', data, callback, '',
- 'api/volunteer/volunteer/rankingList');
- // 活动列表
- export const activityLists = (data, callback) => get('api/activity/activity/lists' + queryParams(data, true),
- callback);
- // 活动详情
- export const activityDetails = (data, callback) => get('api/activity/activity/details' + queryParams(data, true),
- callback);
- // 志愿者排行详情
- export const rankingDetails = (data, callback) => get('api/volunteer/volunteer/rankingDetails' + queryParams(data,
- true),
- callback);
- // 区域数据统计
- export const regionData = (data, callback) => post('regionData', data, callback, '',
- 'api/volunteer/statistics/regionData');
- // 市级数据统计
- export const cityData = (data, callback) => post('cityData', data, callback, '',
- 'api/volunteer/statistics/cityData');
- // 新闻公告
- export const getNewsNotice = (data, callback) => post('getNewsNotice', data, callback, '',
- 'api/system/notice/getNewsNotice');
- // 打卡
- export const checkIn = (data, callback) => post('checkIn', data, callback, '',
- 'api/content/main_body_user/checkIn');
- // 活动报名
- export const activitySignup = (data, callback) => post('activitySignup', data, callback, '',
- 'api/activity/activity/activitySignup');
- // 我的投稿
- export const getUserContribute = (data, callback) => post('getUserContribute', data, callback, '',
- 'api/content/main_body_user/getUserContribute');
- // 我的荣誉
- export const getUserHonor = (data, callback) => post('getUserHonor', data, callback, '',
- 'api/content/main_body_user/getUserHonor');
- // 轮播
- export const getIndexBanner = (data, callback) => post('getIndexBanner', data, callback, '',
- 'api/content/banner_function/getIndexBanner');
- // 导出
- export const exportPatrolRecord = (data, callback) => post('exportPatrolRecord', data, callback, '',
- 'api/volunteer/patrol_task/exportPatrolRecord');
|