123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- //var bmap = require('/mapjs/bmap-wx.min.js');
- var QQMapWX = require("./utils/qqmap-wx-jssdk.js");
- var map;
- App({
- /**
- * 全局变量
- */
- // apiRoot: "https://wj.songlanyun.com/wjxy/api/", // 正式环境api地址
- apiRoot: 'http://192.168.0.78:8687/qyh/api/',
- // apiRoot: 'https://wjxy.songlanyun.com/wjxy/api/',
- // apiRoot: 'http://47.104.208.8:8802/wjxy/api/',
- // apiRoot: 'http://192.168.0.232:8687/wjxy/api/', //黄理志
- // apiRoot: 'http://192.168.0.186:8687/wjxy/api/',
- siteInfo: require("siteinfo.js"),
- token: "",
- // appAssetsUrl: 'https://pm.lanzhongrenli.com/qmjz/app', //静态资源服务器
- appAssetsUrl: "https://wj.songlanyun.com/wjxy/statics/images/app", //静态资源服务器
- // appAssetsUrl2: 'http://192.168.0.101:8687/wjxy/statics/images/app/images/', //静态资源服务器
- appAssetsUrl2: "https://wj.songlanyun.com/wjxy/statics/images/app/images/", //静态资源服务器
- //自定义参数
- params: {
- pePageToIndex: "",
- },
- bottomLeft: 0,
- sexList: [],
- /**
- * 生命周期函数--监听小程序初始化
- */
- onLaunch: function () {
- let that = this;
- map = new QQMapWX({
- key: "RA3BZ-PSGW4-GZUUX-DDAU7-6B54E-KJFQ7", // 必填
- });
- console.log("首次启动");
- const updateManager = wx.getUpdateManager();
- updateManager.onCheckForUpdate(function (res) {
- // 请求完新版本信息的回调
- console.log(res.hasUpdate);
- });
- updateManager.onUpdateReady(function () {
- wx.showModal({
- title: "更新提示",
- content: "新版本已经准备好,是否重启应用?",
- success(res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate();
- }
- },
- });
- });
- updateManager.onUpdateFailed(function () {
- // 新版本下载失败
- wx.showToast({
- title: "版本更新失败,请检查网络!",
- icon: "none",
- duration: 1500,
- });
- });
- /* setInterval(function(){
- wx.removeStorageSync('Weather');
- that.getWeaTher();
- console.log("天气已更新");
- },7200000);*/
- //that.getWeaTher();
- // http://zqgj.vaiwan.com
- // this.setApiRoot("http://zqgj.vaiwan.com/zqgj");
- /* wx.getNetworkType({
- success(res) {
- const networkType = res.networkType
- wx.showToast({
- title: '当前网络为' + networkType + '',
- icon: 'none'
- })
- }
- })*/
- //this.getLocal();
- //ios安全区域
- wx.getSystemInfo({
- success: (res) => {
- this.bottomLeft = res.screenHeight - res.safeArea.bottom;
- },
- });
- wx.request({
- url: this.apiRoot + "bizlibrary/infoList/gender",
- method: "get",
- success: function (res) {
- console.log(res);
- if (res.data.code == 0) {
- that.sexList = res.data.dictList;
- }
- },
- });
- // that.font();
- },
- font() {
- wx.loadFontFace({
- family: "FZZhunYuan-M02S",
- global: true,
- source:
- 'url("https://wujiexiaoyuan-wechat.oss-cn-hangzhou.aliyuncs.com/font/FZZhunYuan-M02S.woff2")',
- // source: 'url("https://wujiexiaoyuan-wechat.oss-cn-hangzhou.aliyuncs.com/font/FZZhunYuan-M02S.ttf")',
- success: (msg) => {
- console.log(msg);
- },
- fail: (err) => {
- console.log(err);
- },
- complete: (res) => {
- console.log(res);
- },
- });
- wx.loadFontFace({
- family: "FZCuYuan-M03",
- global: true,
- source:
- 'url("https://wujiexiaoyuan-wechat.oss-cn-hangzhou.aliyuncs.com/font/yuanGBK.woff2")',
- // source: 'url("https://wujiexiaoyuan-wechat.oss-cn-hangzhou.aliyuncs.com/font/yuanGBK.ttf")',
- success: (msg) => {
- console.log(msg);
- },
- fail: (err) => {
- console.log(err);
- },
- complete: (res) => {
- console.log(res);
- },
- });
- },
- getLocal() {
- const _this = this;
- wx.getLocation({
- type: "gcj02",
- success(res) {
- const latitude = res.latitude;
- const longitude = res.longitude;
- //通过【小程序定位】获取经纬度,在通过第三方sdk获取的地址信息
- _this.pointToAddress(latitude, longitude, function (address) {
- if (address) {
- wx.setStorageSync("CHOOSECITY", {
- cityName: address.city,
- areaName: address.district,
- });
- let pages = getCurrentPages();
- let prevpage = pages[pages.length - 1];
- if (prevpage.hasOwnProperty("loadCity")) {
- prevpage.loadCity();
- }
- }
- });
- },
- fail() {
- let pages = getCurrentPages();
- let prevpage = pages[pages.length - 1];
- if (prevpage.hasOwnProperty("loadCity")) {
- prevpage.loadCity();
- }
- },
- });
- },
- // 定义 pointToAddress 方法
- pointToAddress: function (latitude, longitude, callback) {
- var _this = this;
- // 调用接口
- map.reverseGeocoder({
- location: {
- latitude: latitude,
- longitude: longitude,
- },
- success: function (res) {
- // 解析成功返回地址
- callback(res.result.ad_info);
- },
- fail: function (res) {
- console.log(res);
- },
- complete: function (res) {},
- });
- },
- /**
- * 当小程序启动,或从后台进入前台显示,会触发 onShow
- */
- /*
- onShow: function (options) {
- // 获取小程序基础信息
- this.getWxappBase(function (wxapp) {
- // 设置navbar标题、颜色
- wx.setNavigationBarColor({
- frontColor: wxapp.navbar.top_text_color.text,
- backgroundColor: wxapp.navbar.top_background_color
- })
- });
- },*/
- onShow: function (ops) {
- var that = this;
- wx.checkSession({
- success: function () {
- console.log("当前登录状态:有效");
- },
- fail: function () {},
- });
- wx.onNetworkStatusChange(function (res) {
- if (res.isConnected) {
- if (res.networkType !== "wifi") {
- wx.showToast({
- title: "注意!您正在使用" + res.networkType + "网络",
- icon: "none",
- });
- }
- }
- });
- },
- getWeaTher: function () {
- if (!wx.getStorageSync("Weather")) {
- // 新建百度地图对象
- var BMap = new bmap.BMapWX({
- ak: "pSzxYKshUcuo1Y9pPrbFs6r7LGvx8sxg",
- });
- var fail = function (data) {
- // console.log(data)
- };
- var success = function (data) {
- var weatherData = data.currentWeather[0];
- /* weatherData = '城市:' + weatherData.currentCity + '\n' + 'PM2.5:' + weatherData.pm25 + '\n' + '日期:' + weatherData.date + '\n' + '温度:' + weatherData.temperature + '\n' + '天气:' + weatherData.weatherDesc + '\n' + '风力:' + weatherData.wind + '\n';*/
- //Weather(weatherData.weatherDesc, _this, weatherData);
- wx.setStorageSync("Weather", weatherData);
- };
- // 发起weather请求
- BMap.weather({
- fail: fail,
- success: success,
- });
- }
- },
- /**
- * 设置api地址
- */
- setApiRoot: function () {
- //this.apiRoot = this.siteInfo.siteroot + '/api/';
- },
- /**
- * 获取小程序基础信息
- */
- /*
- getWxappBase: function (callback) {
- let App = this;
- App._get('wxapp/base', {}, function (result) {
- // 记录小程序基础信息
- wx.setStorageSync('wxapp', result.data.wxapp);
- callback && callback(result.data.wxapp);
- }, false, false);
- },*/
- /**
- * 显示成功提示框
- */
- showSuccess: function (msg, callback) {
- wx.showToast({
- title: msg,
- icon: "success",
- success: function () {
- callback &&
- setTimeout(function () {
- callback();
- }, 1500);
- },
- });
- },
- /**
- * 显示失败提示框
- */
- showError: function (msg, callback) {
- wx.showToast({
- title: msg,
- icon: "none",
- duration: 2000,
- success: function (res) {
- callback && callback();
- },
- });
- },
- /**
- * get请求
- */
- _get: function (url, data, success, fail, complete) {
- wx.showNavigationBarLoading();
- let App = this;
- // 构造请求参数
- data = data || {};
- wx.request({
- url: App.apiRoot + url,
- data: data,
- method: "get",
- success: function (res) {
- wx.hideNavigationBarLoading();
- wx.hideLoading();
- if (res.statusCode !== 200 || typeof res.data !== "object") {
- return false;
- }
- if (res.data.code === -1) {
- // 登录态失效, 重新登录
- return false;
- } else {
- success && success(res.data);
- }
- },
- fail: function (res) {
- wx.hideNavigationBarLoading();
- // console.log(res);
- App.showError(res.errMsg, function () {
- fail && fail(res);
- });
- },
- complete: function (res) {
- wx.hideNavigationBarLoading();
- complete && complete(res);
- },
- });
- },
- /**
- * post提交
- */
- _post_form: function (url, header, data, success, fail, complete) {
- wx.showNavigationBarLoading();
- let App = this;
- wx.request({
- url: App.apiRoot + url,
- header: {
- "content-type": header,
- },
- method: "POST",
- data: data,
- success: function (res) {
- wx.showNavigationBarLoading();
- wx.hideLoading();
- if (res.statusCode !== 200 && typeof res.data.code !== 1) {
- App.showError("网络请求出错");
- return false;
- }
- if (res.data.code === -1) {
- // 登录态失效, 重新登录
- App.doLogin(function () {
- App._post_form(url, data, success, fail);
- });
- return false;
- } else if (res.data.code === 0) {
- success && success(res.data);
- } else if (res.data.retCode === "000000") {
- success && success(res.data);
- return;
- } else {
- var msg = "";
- if (res.data.message) {
- msg = res.data.message;
- } else if (res.data.msg) {
- msg = res.data.msg;
- }
- App.showError(msg);
- success && success(res.data);
- return false;
- }
- },
- fail: function (res) {
- wx.showNavigationBarLoading();
- App.showError(res.errMsg, function () {
- fail && fail(res);
- });
- },
- complete: function (res) {
- complete && complete(res);
- wx.hideNavigationBarLoading();
- },
- });
- },
- // put 请求
- _put_form: function (url, header, data, success, fail, complete) {
- wx.showNavigationBarLoading();
- let App = this;
- wx.request({
- url: App.apiRoot + url,
- header: {
- "content-type": header,
- },
- method: "PUT",
- data: data,
- success: function (res) {
- wx.showNavigationBarLoading();
- wx.hideLoading();
- if (res.statusCode !== 200 && typeof res.data.code !== 1) {
- App.showError("网络请求出错");
- return false;
- }
- if (res.data.code === -1) {
- // 登录态失效, 重新登录
- App.doLogin(function () {
- App._post_form(url, data, success, fail);
- });
- return false;
- } else if (res.data.code === 0) {
- success && success(res.data);
- } else if (res.data.retCode === "000000") {
- success && success(res.data);
- return;
- } else {
- var msg = "";
- if (res.data.message) {
- msg = res.data.message;
- } else if (res.data.msg) {
- msg = res.data.msg;
- }
- // App.showError(msg);
- console.log(msg, 11111111);
- success && success(res.data);
- wx.showToast({
- title: msg,
- icon: "none",
- duration: 2000,
- });
- return false;
- }
- },
- fail: function (res) {
- wx.showNavigationBarLoading();
- App.showError(res.errMsg, function () {
- fail && fail(res);
- });
- },
- complete: function (res) {
- complete && complete(res);
- wx.hideNavigationBarLoading();
- },
- });
- },
- /**
- * 对象转URL
- */
- urlEncode: function urlencode(data) {
- var _result = [];
- for (var key in data) {
- var value = data[key];
- if (value.constructor == Array) {
- value.forEach(function (_value) {
- _result.push(key + "=" + _value);
- });
- } else {
- _result.push(key + "=" + value);
- }
- }
- return _result.join("&");
- },
- city: function () {
- return cityCode;
- },
- /**
- * 设置当前页面标题
- */
- /*
- setTitle: function() {
- let App = this,
- wxapp;
- if (wxapp = wx.getStorageSync('wxapp')) {
- wx.setNavigationBarTitle({
- title: wxapp.navbar.wxapp_title
- });
- } else {
- App.getWxappBase(function() {
- App.setTitle();
- });
- }
- },
- */
- });
|