123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- // let BASE_Server = "http://127.0.0.1:8329"
- // let BASE_Server = "https://192.168.1.109:8080"
- let BASE_Server = "https://sookajs.top:28080"
- let app = getApp()
- //-----------------------------登录,获取token-----------------------------------
- function init_userInfo() {
- if (app.globalToken == null) {
- wx.getUserProfile({
- desc: 'desc',
- success: (res) => {
- getSysUserInfo(res.userInfo)
- },
- fail: res => {
-
- }
- })
- }
- }
- function getSysUserInfo(info) {
-
- let that = this
- wx.login({
- success(res) {
- var code = res.code
- var data = {
- wxCode: code,
- wxNickName: info.nickName,
- wxAvatarUrl: info.avatarUrl
- }
- // http.send_post_login("/minapp/AppLoginController/appLogin",data)
- send_post("/auth/applogin", data, loginSuccess)
- },
- fail(res) {
-
- }
- })
- }
- function loginSuccess(res) {
- if (res.data.code != 200) {
- wx.showToast({
- title: res.data.msg != null ? res.data.msg : '',
- icon: "none"
- })
- } else {
- app.globalToken = res.data.access_token
- //登录成功,获取首页数据
- this.initIndexPage()
- }
- }
- //------------------------------------------------------------------
- /**
- * 携带token json数据 POST请求
- * @param {*} url
- * @param {*} data
- * @param {*} successfun
- */
- function send_post(url, data, successfun) {
- if (app.globalToken == null) {
- wx.showToast({
- title: '尚未登录,登录后即可使用',
- icon: 'none'
- })
- return
- }
- wx.request({
- url: BASE_Server + url, //仅为示例,并非真实的接口地址
- method: "POST",
- header: {
- 'content-type': 'application/json',
- 'Authorization': 'Bearer ' + app.globalToken
- },
- data: data,
- success(res) {
- // var d = decodeURIComponent(decodeURIComponent(res.data.data))
- // var json = JSON.parse(d)
-
- authToken(res.data)
- successfun(res.data)
- },
- fail(res){
- // console.log("TAG","返回数据:"+res.errno+'_'+res.errMsg)
- wx.showToast({
- title: "网络请求失败",
- })
- }
- })
- }
- /**
- * 携带token表单数据POST请求
- * @param {*} url
- * @param {*} data
- * @param {*} successfun
- */
- function post(url, data, successfun) {
- if (app.globalToken == null) {
- wx.showToast({
- title: '尚未登录,登录后即可使用',
- icon: 'none'
- })
- return
- }
- wx.request({
- url: BASE_Server + url, //仅为示例,并非真实的接口地址
- method: "POST",
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- 'Authorization': 'Bearer ' + app.globalToken
- },
- data: data,
- success(res) {
- successfun(res.data)
- },
- fail(res){
- wx.showToast({
- title: "网络请求失败",
- })
- }
- })
- }
- /**
- * 无token json数据使用的POST请求
- * @param {*} url
- * @param {*} data
- * @param {*} successfun
- */
- function post_token(url, data, successfun) {
-
- wx.request({
- url: BASE_Server + url, //仅为示例,并非真实的接口地址
- method: "POST",
- header: {
- 'content-type': 'application/json',
- 'Authorization': 'Bearer ' + app.globalToken
- },
- data: data,
- success(res) {
-
- authToken(res.data)
- successfun(res.data)
- },
- fail(res){
- wx.showToast({
- title: "网络请求失败",
- icon:'none',
- })
- }
- })
- }
- /**
- * 备用的GET请求
- * @param {*} url
- * @param {*} data
- * @param {*} successfun
- */
- function get(url, data, successfun) {
- if (app.globalToken == null) {
- wx.showToast({
- title: '尚未登录,登录后即可使用',
- icon: 'none'
- })
- return
- }
- wx.request({
- url: BASE_Server + url, //仅为示例,并非真实的接口地址
- method: "GET",
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- 'Authorization': 'Bearer ' + app.globalToken
- },
- params: data,
- success(res) {
- successfun(res.data)
- },
- fail(res){
- wx.showToast({
- title: "网络请求失败",
- })
- }
- })
- }
- /**
- * 携带token使用的GET请求
- * @param {*} url
- * @param {*} data
- * @param {*} successfun
- */
- function send_get(url, data, successfun) {
-
- if (app.globalToken == null) {
- wx.showToast({
- title: '尚未登录,登录后即可使用',
- icon: 'none'
- })
- return
- }
- wx.request({
- url: BASE_Server + url, //仅为示例,并非真实的接口地址
- method: "GET",
- header: {
- 'content-type': 'application/json',
- 'Authorization': 'Bearer ' + app.globalToken
- },
- data: data,
- success(res) {
- // var d = decodeURIComponent(decodeURIComponent(res.data.data))
- // var json = JSON.parse(d)
-
- authToken(res.data)
- successfun(res.data)
- },
- fail(res){
- wx.showToast({
- title: "网络请求失败",
- icon:'none',
- })
- }
- })
- }
- /**
- * 无token 可使用的 GET 请求
- * @param {*} url
- * @param {*} data
- * @param {*} successfun
- */
- function get_token(url, data, successfun) {
- wx.request({
- url: BASE_Server + url, //仅为示例,并非真实的接口地址
- method: "GET",
- header: {
- 'content-type': 'application/json',
- 'Authorization': 'Bearer ' + app.globalToken
- },
- data: data,
- success(res) {
- // var d = decodeURIComponent(decodeURIComponent(res.data.data))
- // var json = JSON.parse(d)
-
- authToken(res.data)
- successfun(res.data)
- },
- fail(res){
- wx.showToast({
- title: "网络请求失败",
- icon:'none',
- })
- }
- })
- }
- function send_postdecode(url, data, successfun) {
- wx.request({
- url: BASE_Server + url, //仅为示例,并非真实的接口地址
- method: "POST",
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data: data,
- success(res) {
- var json = JSON.parse(res.data)
- successfun(json)
- }
- })
- }
- function send_photo(data, successfun) {
- var that = this
- for (let i = 0; i < data.length; i++) {
-
-
- wx.uploadFile({
- url: BASE_Server + "/FileUpLoadController/upload.action", //仅为示例,非真实的接口地址
- filePath: data[i] + "",
- name: 'file',
- success: function (res) {
- var json = JSON.parse(res.data)
- var sss = JSON.parse(decodeURIComponent(decodeURIComponent(json.data)));
- wx.setStorageSync('filename' + (i + 1), sss.data.filename);
- successfun(sss)
- }
- })
- }
- }
- function send(data, successfun) {
- var that = this
- wx.uploadFile({
- url: BASE_Server + "/CarIDScanController/carIduploadGetNumber.action", //仅为示例,非真实的接口地址
- filePath: data[0] + "",
- name: 'file',
- success: function (res) {
- var json = JSON.parse(res.data)
- var sss = JSON.parse(decodeURIComponent(decodeURIComponent(json.data)));
- // wx.setStorageSync("carnumber", sss.data.carNumber)
- successfun(sss)
- },
- fail: function (res) {}
- })
- }
- module.exports = {
- BASE_Server: BASE_Server,
- send_photo: send_photo,
- send: send,
- post: post,
- send_post: send_post,
- post_token: post_token,
- // wxpost: wxpost,
- get: get,
- send_get:send_get,
- get_token:get_token,
- send_postdecode: send_postdecode,
- // send_post_login,
- showLoading,
- hideLoading,
- }
- function showLoading() {
- wx.showLoading({
- title: '加载中...',
- mask: true,
- })
- }
- function hideLoading() {
- wx.hideLoading()
- }
- function authToken(res){
- if(res.code==401){//登录token过期状态码
- wx.clearStorage({
- success:(res)=>{
- wx.reLaunch({
- url: '../denglu/denglu',
- })
- }
- })
-
- }
- }
-
- // function wxpost(url, data, successfun) {
- // wx.request({
- // url: BASE_Server + url, //仅为示例,并非真实的接口地址
- // method: "POST",
- // header: {
- // 'content-type': 'application/json',
- // 'Authorization': 'Bearer ' + app.globalToken
- // },
- // data: data,
- // success(res) {
- // successfun(res.data)
- // }
- // })
- // }
|