Commit 8dd1fee2 authored by 石盼盼's avatar 石盼盼

首次提交

parent d462e4a2
// app.js
App({
onLaunch() {
this.isreload();
this.getVision();
// this.getToken();
this.getSessionKey()
},
// 小程序是否有新版本
isreload: function () {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦,请您删除当前小程序,重新搜索打开!'
})
})
}
})
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试!'
})
}
},
getVision() {
const accountInfo = wx.getAccountInfoSync();
console.log(accountInfo)
if (accountInfo.miniProgram.envVersion == 'develop') { // 开发板
this.globalData.globalUrl = 'https://repairtest.zeruiedu.com'
} else if (accountInfo.miniProgram.envVersion == 'trial') { // 体验版
this.globalData.globalUrl = 'https://repairtest.zeruiedu.com'
} else if (accountInfo.miniProgram.envVersion == 'release') { // 正式版
this.globalData.globalUrl = 'https://repair.zeruiedu.com'
} else {
this.globalData.globalUrl = 'https://repairtest.zeruiedu.com'
}
console.log(this.globalData.globalUrl)
},
// 将token从缓存中 赋值到全局变量
getToken: function () {
var that = this
try {
var token = wx.getStorageSync('token')
var userInfo = wx.getStorageSync('userInfo')
console.log("token", token)
if (token) {
that.globalData.token = token
that.globalData.userInfo = userInfo
} else { }
} catch (e) { }
},
// 登录获取sessionkey 提交后台换取基本openid unionid
getSessionKey: function (cb, cb1) {
var that = this
// 调用登录接口
wx.login({
success: function (res) {
that.codeChangeToken(res.code, cb, cb1)
}
})
},
saveUserInfo: function (info, cb) {
var that = this
if (that.globalData.first_token !== '') {
wx.checkSession({
success() {
wx.request({
url: that.globalData.globalUrl + '/api/v1.0/saveInfo',
method: 'GET',
header: {
Authorization: that.globalData.first_token,
// token: 'sys',
},
data: {
encryptedData: encodeURIComponent(info.encryptedData),
iv: encodeURIComponent(info.iv),
token: that.globalData.token
},
success: function (res) {
if (res.data.meta.code === 200) {
wx.setStorageSync('userInfo', JSON.parse(info.rawData))
that.globalData.userInfo = JSON.parse(info.rawData)
that.globalData.hasTel = res.data.data.telephone
if (res.data.data.telephone) {
wx.setStorageSync('userTel', res.data.data.telephone)
}
typeof cb == "function" && cb()
} else {
wx.showToast({
title: res.data.meta.message,
icon: 'none'
})
}
}
})
},
fail() {
that.getSessionKey(() => that.saveUserInfo(info, cb))
}
})
} else {
that.getSessionKey(() => that.saveUserInfo(info, cb))
}
},
// sessionkey 换取token
codeChangeToken(code, cb) {
// 发起网络请求
var that = this
wx.request({
url: 'https://new.open.xueyoubangedu.com/openxcx/auth',
data: {
code: code,
app_type: 'repair',
authorizer_appid: "wx4c343d3425b433cc"
},
success: function (res) {
if (res.data.code === 200) {
wx.setStorageSync('token', res.data.data.token)
that.globalData.token = res.data.data.token
// login
wx.request({
url: that.globalData.globalUrl + '/api/v1.0/login',
data: {
token: res.data.data.token
},
method: 'GET',
success: function (res) {
if (res.data.meta.code === 200) {
wx.setStorageSync('token', res.data.data.token)
that.globalData.first_token = res.data.data.token
typeof cb == "function" && cb()
} else {
wx.showToast({
title: res.data.meta.message,
icon: 'none'
})
}
}
})
} else {
console.log(res)
}
}
})
},
globalData: {
userInfo: null,
first_token: '',//login接口返回来的token
token: '',//用户token
globalUrl: '', // 全局Url
app_id: 'wxafaf02db6f71f4a3',
backurl: '', // 全局跳转页面路径
tjgs_fresh:false,
hasTel: false, // 是否手机号登录过
}
})
{
"pages":[
"pages/translate/translate"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#FFF",
"navigationBarTitleText": "宣讲会",
"navigationBarTextStyle":"black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
/**app.wxss**/
@import 'iconfont/iconfont.wxss';
/* .container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
} */
/* view,
text {
line-height: 1;
color: #000000;
} */
view,
text,
textarea,
input {
box-sizing: border-box !important;
-moz-box-sizing: border-box !important;
-webkit-box-sizing: border-box !important;
}
.title{
color: #000;
font-size: 36rpx;
margin-bottom: 20rpx;
}
/* 一行 */
.text-line-one {
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-webkit-text-overflow: ellipsis;
-moz-text-overflow: ellipsis;
white-space: nowrap;
}
/* 两行 */
.text-line-two {
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
height: 85rpx;
}
.no-line {
border: none !important;
}
/* 空白页 */
.noneBox {
padding: 140rpx 0 0;
align-items: center;
font-size: 28rpx;
color: #999;
}
.noneBox image {
width: 400rpx;
height: 400rpx;
margin-bottom: 30rpx;
}
.column {
display: flex;
flex-direction: column;
}
/* flex兼容性 */
/* 父元素-横向排列(主轴) */
.flex-h {
display: -webkit-box;
/* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-box;
/* OLD - Firefox 19- (buggy but mostly works) */
display: -ms-flexbox;
/* TWEENER - IE 10 */
display: -webkit-flex;
/* NEW - Chrome */
display: flex;
/* NEW, Spec - Opera 12.1, Firefox 20+ */
/* 09版 */
-webkit-box-orient: horizontal;
/* 12版 */
-webkit-flex-direction: row;
-moz-flex-direction: row;
-ms-flex-direction: row;
-o-flex-direction: row;
flex-direction: row;
}
/* 父元素-纵向排列(主轴) */
.flex-v {
display: -webkit-box;
/* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-box;
/* OLD - Firefox 19- (buggy but mostly works) */
display: -ms-flexbox;
/* TWEENER - IE 10 */
display: -webkit-flex;
/* NEW - Chrome */
display: flex;
/* NEW, Spec - Opera 12.1, Firefox 20+ */
/* 09版 */
-webkit-box-orient: vertical;
/* 12版 */
-webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
-o-flex-direction: column;
flex-direction: column;
}
.flex-hr {
display: -webkit-box;
/* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-box;
/* OLD - Firefox 19- (buggy but mostly works) */
display: -ms-flexbox;
/* TWEENER - IE 10 */
display: -webkit-flex;
/* NEW - Chrome */
display: flex;
/* NEW, Spec - Opera 12.1, Firefox 20+ */
/* 09版 */
-webkit-box-orient: horizontal;
/* 12版 */
-webkit-flex-direction: row-reverse;
-moz-flex-direction: row-reverse;
-ms-flex-direction: row-reverse;
-o-flex-direction: row-reverse;
flex-direction: row-reverse;
}
.flex-hc {
-webkit-box-pack: center;
-webkit-justify-content: center;
-moz-justify-content: center;
-ms-justify-content: center;
-o-justify-content: center;
justify-content: center;
}
.flex-hb {
-webkit-box-pack: space-between;
-webkit-justify-content: space-between;
-moz-justify-content: space-between;
-ms-justify-content: space-between;
-o-justify-content: space-between;
justify-content: space-between;
}
.flex-ha {
-webkit-box-pack: space-around;
-webkit-justify-content: space-around;
-moz-justify-content: space-around;
-ms-justify-content: space-around;
-o-justify-content: space-around;
justify-content: space-around;
}
.flex-vc {
/* 09版 */
-webkit-box-align: center;
/* 12版 */
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
-o-align-items: center;
align-items: center;
}
/* 父元素-横向换行 */
.flex-hw {
/* 09版 */
/*-webkit-box-lines: multiple;*/
/* 12版 */
-webkit-flex-wrap: wrap;
-moz-flex-wrap: wrap;
-ms-flex-wrap: wrap;
-o-flex-wrap: wrap;
flex-wrap: wrap;
}
\ No newline at end of file
@font-face {
font-family: "iconfont"; /* Project id 2743237 */
src: url('//at.alicdn.com/t/font_2743237_bgxgkhue909.woff2?t=1629361358485') format('woff2'),
url('//at.alicdn.com/t/font_2743237_bgxgkhue909.woff?t=1629361358485') format('woff'),
url('//at.alicdn.com/t/font_2743237_bgxgkhue909.ttf?t=1629361358485') format('truetype');
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-weixin1:before {
content: "\e618";
}
.icon-wode:before {
content: "\e605";
}
.icon-yanzhengma:before {
content: "\e667";
}
.icon-shouji:before {
content: "\e654";
}
.icon-xingxing:before {
content: "\e6cb";
}
.icon-dianhua:before {
content: "\e601";
}
.icon-banshou:before {
content: "\e60d";
}
.icon-chenggong:before {
content: "\e67b";
}
.icon-2cha:before {
content: "\e88a";
}
.icon-zhaopian:before {
content: "\e687";
}
.icon-fenye-xiayiye:before {
content: "\e617";
}
.icon-gongdan:before {
content: "\e600";
}
const app = getApp()
import { Base } from '../../utils/base';
import apiList from '../../utils/apiList';
const base = new Base()
Page({
data: {
telphone: ''
},
onLoad: function (options) {
},
// getPhoneNumber: function(e){
// if(e.detail.errMsg == 'getPhoneNumber:ok'){
// wx.request({
// url: 'https://new.open.xueyoubangedu.com/openxcx/auth',
// data: {
// code: code,
// app_type: 'repair',
// authorizer_appid: "wx4c343d3425b433cc"
// },
// success: function (res) {
// if (res.data.code === 200) {
// wx.setStorageSync('token', res.data.data.token)
// that.globalData.token = res.data.data.token
// // login
// wx.request({
// url: that.globalData.globalUrl + '/api/v1.0/login',
// data: {
// token: res.data.data.token
// },
// method: 'GET',
// success: function (res) {
// if (res.data.meta.code === 200) {
// wx.setStorageSync('token', res.data.data.token)
// that.globalData.first_token = res.data.data.token
// typeof cb == "function" && cb()
// } else {
// wx.showToast({
// title: res.data.meta.message,
// icon: 'none'
// })
// }
// }
// })
// } else {
// console.log(res)
// }
// }
// }),
// }else{
// base.toast('授权失败,无法查看')
// }
// },
getPhoneNumber: function (e) {
console.log('绑定手机号的', e)
if (e.detail.errMsg == 'getPhoneNumber:ok') {
wx.request({
url: 'https://new.open.xueyoubangedu.com/openxcx/switchPhone',
data: {
authorizer_appid: 'wx4c343d3425b433cc',
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
token: app.globalData.token
},
method: 'POST',
success: function (res) {
console.log(res, 11111111)
if (res.data.meta.code === 200) {
let params = {
url: apiList.firstSave_phone,
data: {
user_phone: res.data.data.phoneNumber
},
type: 'POST',
callback: (data) => {
app.globalData.userTel = res.data.data.phoneNumber
try {
wx.setStorageSync('userTel', res.data.data.phoneNumber)
} catch (e) { }
if (app.globalData.backurl) {
if (app.globalData.backurl.indexOf('/pages/tabbar/index/index') != -1 || app.globalData.backurl.indexOf('/pages/tabbar/my/my') != -1) {
wx.switchTab({
url: app.globalData.backurl,
})
} else {
wx.redirectTo({
url: app.globalData.backurl
})
}
} else {
wx.switchTab({
url: '/pages/tabbar/my/my',
})
}
}
}
base.newRequest(params)
}
}
})
} else {
base.toast('授权失败,无法查看')
}
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<view class="loginBox">
<view class="logo-view">
<image src="/images/logo.png"></image>
</view>
<view class="title">E速报修</view>
<view class="desc">为保护您的账号资产,我们需要您的手机号授权, 以同步支付的商品信息。</view>
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">同意授权</button>
</view>
\ No newline at end of file
.loginBox {
padding-top: 174rpx;
}
.logo-view {
margin: 0 auto 40rpx auto;
}
.logo-view image {
display: block;
margin: 0 auto;
width: 216rpx;
height: 216rpx;
}
.loginBox .title {
font-weight: bold;
text-align: center;
font-size: 38rpx;
font-weight: bold;
color: #000000;
}
.desc {
width: 540rpx;
margin: 30rpx auto 85rpx auto;
font-size: 24rpx;
color: #999;
text-align: center;
line-height: 2;
}
.loginBox button {
align-items: center;
justify-content: center;
width: 620rpx !important;
height: 82rpx !important;
background: linear-gradient(270deg, #0054FF, #1965FF);
color: #fff;
border-radius: 41rpx;
margin: 0 auto;
padding: 0 !important;
font-size: 30rpx;
border: none;
outline: none;
line-height: 82rpx;
}
const app = getApp()
import {
Base
} from '../../../utils/base.js';
const base = new Base();
Page({
data: {
canIUseGetUserProfile: false,
},
onLoad: function (options) {
var that = this
if (wx.canIUse('getUserProfile') && wx.getUserProfile) {
that.setData({
canIUseGetUserProfile: true
})
} else {
that.setData({
canIUseGetUserProfile: false
})
}
console.log(this.data.canIUseGetUserProfile, '11111111111111')
},
// 授权获取用户信息
getUserProfile() {
wx.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
// console.log("res------用于完善会员资料", res)
if(res.errMsg == "getUserProfile:ok") {
app.saveUserInfo(res, this.showUserInfo)
} else {
// console.log("res.errMsg------用于完善会员资料", res.errMsg)
base.toast(res.errMsg)
}
},
fail: (err) => {
base.toast('请先授权,才能验证身份')
}
})
},
// 旧版本 授权获得用户信息
userInfoHandler: function (e) {
let that = this
if (e.detail.errMsg == 'getUserInfo:ok') {
app.saveUserInfo(e.detail, this.showUserInfo)
} else {
base.toast('请先授权,才能验证身份')
}
},
showUserInfo: function () {
console.log(app.globalData.hasTel)
if (app.globalData.hasTel) {
base.toast('登录成功')
setTimeout(() => {
if (app.globalData.backurl) {
if (app.globalData.backurl.indexOf('/pages/tabbar/my/my') != -1 || app.globalData.backurl.indexOf('/pages/tabbar/index/index') != -1 || app.globalData.backurl.indexOf('/pages/tabbar/index/index') != -1) {
wx.switchTab({
url: app.globalData.backurl,
})
} else {
wx.redirectTo({
url: app.globalData.backurl
})
}
} else {
wx.switchTab({
url: '/pages/personal/personal',
})
}
}, 800)
} else {
wx.navigateTo({
url: '/pages/bindTel/bindTel',
})
}
},
})
\ No newline at end of file
{
"usingComponents": {},
"navigationBarTitleText": "E速报修"
}
\ No newline at end of file
<view class="loginbox">
<image class="title_img" src="/images/logo.png"></image>
<view class="title_tip"> E速报修</view>
<button class="title_btn flex-h flex-vc flex-hc" wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile">
<text class="iconfont icon-weixin1"></text> 微信一键注册/登录
</button>
<button class="title_btn flex-h flex-vc flex-hc" wx:else open-type="getUserInfo" bindgetuserinfo="userInfoHandler">
<text class="iconfont icon-weixin1"></text> 微信一键注册/登录
</button>
<view class="small_tip">请登录查看更多内容</view>
</view>
\ No newline at end of file
page {
background: #fff;
}
.loginbox {
text-align: center;
padding-top: 271rpx;
}
.title_img {
width: 207rpx;
height: 207rpx;
margin-bottom: 25rpx;
}
.title_tip {
font-size: 36rpx;
font-weight: bold;
margin-bottom: 192rpx;
}
.title_btn {
width: 620rpx !important;
height: 82rpx;
background: linear-gradient(270deg, #0054FF, #1965FF);
border-radius: 41rpx;
font-size: 32rpx;
color: #FFFFFF;
}
.title_btn text {
color: #fff;
font-size: 40rpx;
margin-right: 5rpx;
}
.small_tip {
width: 100%;
text-align: center;
font-size: 26rpx;
color: #989794;
margin-top: 40rpx;
}
\ No newline at end of file
// pages/translate/translate.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<view class="img">
<image src="/images/ceshi.png"></image>
</view>
\ No newline at end of file
page{
width: 100%;
height: 100%;
}
.img{
width: 100%;
height: 100%;
}
.img image{
width: 100%;
height: 100%;
}
\ No newline at end of file
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": false,
"es6": true,
"enhance": false,
"postcss": true,
"preloadBackgroundData": false,
"minified": true,
"newFeature": false,
"coverView": true,
"nodeModules": false,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": false,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"enableEngineNative": false,
"bundle": false,
"useIsolateContext": true,
"useCompilerModule": true,
"userConfirmedUseCompilerModuleSwitch": false,
"userConfirmedBundleSwitch": false,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true
},
"compileType": "miniprogram",
"libVersion": "2.16.1",
"appid": "wxafaf02db6f71f4a3",
"projectname": "%E6%8A%A5%E4%BF%AE%E5%B0%8F%E7%A8%8B%E5%BA%8F",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
}
}
\ No newline at end of file
{
"setting": {},
"condition": {
"plugin": {
"list": []
},
"game": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": [
{
"name": "提交工单页面",
"pathName": "pages/detail/index/index",
"query": "",
"scene": null
},
{
"name": "工单页面",
"pathName": "pages/tabbar/my/my",
"query": "",
"scene": null
},
{
"name": "登录",
"pathName": "pages/login/index/index",
"query": "",
"scene": null
},
{
"name": "评价",
"pathName": "pages/order/evaluate/evaluate",
"query": "id=62",
"scene": null
},
{
"name": "pages/order/lookCost/lookCost",
"pathName": "pages/order/lookCost/lookCost",
"query": "",
"scene": null
}
]
}
}
}
\ No newline at end of file
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
\ No newline at end of file
module.exports = {
test: '/api/test', // 测试
repair_order: '/api/v1.0/repair/order', // 提交报修单
repair_index: '/api/v1.0/repair/index',//首页参数:维修类型;区域;预约时间
repair_list: '/api/v1.0/repair/list', // 报修单列表
repair_withdrawn: '/api/v1.0/repair/withdrawn', // 学生撤回报修单接口
repair_complaint: '/api/v1.0/repair/complaint', // 投诉接口
repair_appraisal: '/api/v1.0/repair/appraisal', // 评价接口
material_list: '/api/v1.0/material/list', // 收费明细接口
material_signPay: '/api/v1.0/material/signPay', // 收费明细接口
firstSave_phone: '/api/v1.0/firstSavePhone', // 首次保存手机号接口
}
\ No newline at end of file
// 公共函数库
const app = getApp()
const qiniuUploader = require("./qiniuUploader.js");
class Base {
constructor() {
this.baseUrl = app.globalData.globalUrl;
}
newRequest(params, flag = false, tips = true) {
let that = this
if (!params.type) {
params.type = 'GET'
}
// 版本
// if (!params.version) {
// params.version = 'v1.0/'
// }
// var cur_url = that.baseUrl + params.version + params.url
var cur_url = that.baseUrl + params.url
if (params.otherUrl) {
cur_url = params.otherUrl
}
wx.request({
url: cur_url,
data: params.data,
method: params.type,
header: {
Authorization: app.globalData.first_token
// 'token': 'sys',
},
success: function (res) {
params.confirmback && params.confirmback(res) //请求完成后回调
if (wx.showLoading()) {
wx.hideLoading() //隐藏加载动画
}
if (res.statusCode == 200) {
let rstcode = res.data.meta.code, msg = res.data.meta.message
// todo: 状态码判断
if (rstcode == 200) {
params.callback && params.callback(res.data.data) // 请求成功
} else if (rstcode == '-400') { // 400 token过期
if (!flag) {
that.changeToken(params)
// app.getSessionKey(function () {
// that.newRequest(params, true,tips=true)
// })
}
} else if (rstcode == '404') {
wx.showModal({
title: '错误',
content: '网络请求失败'
})
} else {
params.errorback && params.errorback(res) // 错误回调
if (tips) {
wx.showToast({
title: msg,
icon: 'none',
duration: 2000
})
}
}
} else {
if (wx.showLoading()) {
wx.hideLoading() //隐藏加载动画
}
wx.showModal({
title: '错误',
content: '网络请求失败'
})
}
}
})
}
changeToken(params){
wx.showLoading({
title: '努力加载中...',
})
let that = this
let tokenUrl = that.baseUrl + '/api/v1.0/change/token'
wx.request({
url: tokenUrl,
data: {
},
method:'post',
header: {
'content-type': 'application/json', // 默认值
Authorization: app.globalData.first_token
},
success (res) {
wx.hideLoading() //隐藏加载动画
if (res.statusCode == 200) {
let rstcode = res.data.meta.code
if (rstcode == 200) {
app.globalData.first_token = res.data.data.access_token
that.newRequest(params)
}else{
app.getSessionKey(function () {
that.newRequest(params, true,true)
})
}
}
}
})
}
//富文本
richText(detail) {
if (detail != '' && detail != null && detail != undefined) {
var newDetail = '';
newDetail = detail.replace(/\<[\/]?(section)/g, function (m, m1) {
return m.replace('section', 'div')
});
newDetail = newDetail.replace(/\<[\/]?(ruby)/g, function (m, m1) {
return m.replace('ruby', 'span')
});
newDetail = newDetail.replace(/\<[\/]?(rt)/g, function (m, m1) {
return m.replace('rt', 'span')
});
newDetail = newDetail.replace(/\<[\/]?(rp)/g, function (m, m1) {
return m.replace('rp', 'span')
});
newDetail = newDetail.replace(/\<[\/]?(video)/g, function (m, m1) {
return m.replace('video', 'video')
});
newDetail = newDetail.replace(/(\<img)/g, '$1 class="hellorich"');
newDetail = newDetail.replace(/(\<div)/g, '$1 class="hellorich"');
newDetail = newDetail.replace(/(\<p)/g, '$1 class="hellorich"');
newDetail = newDetail.replace(/(\<video)/g, '$1 class="helloVideo"');
return newDetail;
} else {
return ''
}
}
//判断字符是否为空的方法
stringIsEmpty(str) {
if (typeof str == "undefined" || str == null || str == "") {
return true;
} else {
return false;
}
}
// 判断手机号格式
telChange(tel) {
const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
if (!reg.test(tel)) {
return true
} else {
return false
}
}
// object通过value换取key
findKey(value) {
let arr = value.split('/api/')
let name = arr.length > 1 ? arr[1] : arr[0]
return name.replace(/\//g, "_")
}
trimStrSpace(str) {
return str.replace(/(^\s*)|(\s*$)/g, '')
}
/**
* 提示框
* icon [success,loading,none]
*/
toast(
title,
duration = 2000,
icon = 'none',
image = '',
mask = true,
callback
) {
wx.showToast({
title: title,
icon: icon,
image: image,
duration: duration,
mask: mask,
success: function () {
callback && callback()
}
})
}
modal(
content = '',
callback,
errorback
) {
wx.showModal({
title: "提示",
content: content,
success: function (res) {
if (res.confirm) {
callback && callback()
console.log('用户点击确定')
} else if (res.cancel) {
errorback && errorback()
console.log('用户点击取消')
}
}
})
}
goBack(num) {
var pages = getCurrentPages()
var prevPage = pages[pages.length - parseInt(num)]
prevPage.setData({
isrefresh: true
})
setTimeout(function () {
wx.navigateBack({
delta: parseInt(num-1)
})
}, 800)
}
//七牛上传
initQiniu() {
var options = {
uptokenURL: 'https://repairtest.zeruiedu.com/api/v1.0/upload/token',
domain: 'https://fhxm.xueyoubangedu.com/',
uploadURL: 'https://up-z1.qiniup.com'
};
qiniuUploader.init(options);
}
}
export {
Base
}
\ No newline at end of file
// created by gpake
(function() {
const app = getApp()
var imgTempUrl = [] //上传图片后临时存放容器
var config = {
qiniuUploadURL: '',
qiniuImageURLPrefix: '',
qiniuUploadToken: '',
qiniuUploadTokenURL: '',
qiniuUploadTokenFunction: null
}
module.exports = {
init: init,
upload: upload,
}
// 在整个程序生命周期中,只需要 init 一次即可
// 如果需要变更参数,再调用 init 即可
function init(options) {
config = {
qiniuUploadURL: '',
qiniuImageURLPrefix: '',
qiniuUploadToken: '',
qiniuUploadTokenURL: '',
qiniuUploadTokenFunction: null
};
updateConfigWithOptions(options);
}
function updateConfigWithOptions(options) {
if (options.uploadURL) {
config.qiniuUploadURL = options.uploadURL;
} else {
console.error('qiniu uploader need uploadURL');
}
if (options.uptoken) {
config.qiniuUploadToken = options.uptoken;
} else if (options.uptokenURL) {
config.qiniuUploadTokenURL = options.uptokenURL;
} else if (options.uptokenFunc) {
config.qiniuUploadTokenFunction = options.uptokenFunc;
}
if (options.domain) {
config.qiniuImageURLPrefix = options.domain;
}
}
function upload(i = 0,filePath, success, fail, options) {
if (null == filePath) {
console.error('qiniu uploader need filePath to upload');
return;
}
if (options) {
init(options);
}
if (config.qiniuUploadToken) {
doUpload(i= 0,filePath, success, fail, options);
} else if (config.qiniuUploadTokenURL) {
getQiniuToken(function() {
upload(i = 0,filePath, success, fail, options);
});
} else if (config.qiniuUploadTokenFunction) {
config.qiniuUploadToken = config.qiniuUploadTokenFunction();
} else {
console.error('qiniu uploader need one of [uptoken, uptokenURL, uptokenFunc]');
return;
}
}
function doUpload(i= 0,filePath, success, fail, options) {
var url = config.qiniuUploadURL;
var fileName = filePath[i].split('//')[1];
if (options && options.key) {
fileName = options.key;
}
var formData = {
'token': config.qiniuUploadToken,
'key': fileName
};
wx.uploadFile({
url: url,
filePath: filePath[i],
name: 'file',
formData: formData,
success: function(res) {
// wx.hideLoading();
var dataString = res.data
var dataObject = JSON.parse(dataString);
var imageUrl = config.qiniuImageURLPrefix + dataObject.key;
dataObject.imageURL = imageUrl;
imgTempUrl.push(dataObject)
if (i + 1 < filePath.length) {
doUpload(i + 1, filePath, success)
} else {
setTimeout(()=>{
wx.hideLoading()
},3000)
success(imgTempUrl)
imgTempUrl = []
}
},
fail: function(error) {
wx.hideLoading();
fail(error);
}
}).onProgressUpdate(res => {
var progress = '上传中(' + (i + 1) + '/' + filePath.length + ')'
wx.showLoading({
title: progress,
mask: true
})
})
}
function getQiniuToken(callback) {
// var that = this
wx.request({
url: config.qiniuUploadTokenURL,
data: {
token: app.globalData.token
},
success: function(res) {
console.log(res)
if (res.data.meta.code == 200) {
var token = res.data.data.uptoken;
config.qiniuUploadToken = token;
if (callback) {
callback();
}
} else if (res.data.meta.code == 400) {
app.getSessionKey(function () {
getQiniuToken(callback)
})
}
},
fail: function(error) {
console.log(error);
}
})
}
})();
\ No newline at end of file
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
module.exports = {
formatTime
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment