123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /**
- * @Time 2019-12-12
- * @Author Zhengjingyi
- * @Action 全局公共方法
- */
- import requestUrl from '@/services/config.env.js'
- const _Tools = {
- getComStorage:function(key){// 获取本地Storage
- return new Promise(function(resolve,reject) {
- uni.getStorage({
- key: key,
- success: function (res){
- resolve(res.data)
- },
- fail: function(res){
- reject(false)
- }
- })
- })
- },
- setStorage:function(key,data){// 存储本地Storage
- return new Promise(function(resolve,reject) {
- uni.setStorage({
- key: key,
- data:data,
- success: function (res){
- }
- })
- })
- },
- getStorage:function(){// 获取本地userInfo
- return new Promise(function(resolve,reject) {
- uni.getStorage({
- key: 'userInfo',
- success: function (res){
- resolve(res.data)
- },
- fail: function(res){
- reject(false)
- }
- })
- })
- },
- getStorageAddressKey:function(){// 获取本地地址信息
- return new Promise(function(resolve,reject) {
- uni.getStorage({
- key: 'address_key',
- success: function (res){
- resolve(res.data)
- }
- })
- })
- },
- navigateTo:function(url){
- //路由跳转:页面之间路由跳转
- uni.navigateTo({
- url:url
- })
- },
- redirectTo:function(url){
- //路由跳转:关闭当前页跳转到新页面
- uni.redirectTo({
- url:url
- })
- },
- switchTabTo:function(url){
- //路由跳转:底部 tab页
- uni.switchTab({
- url:url
- })
- },
- getWindowHeight:function(){
- // 获取窗口高度
- const {windowHeight, pixelRatio} = wx.getSystemInfoSync()
- return windowHeight
- },
- adaptRichTextImg:function(res){
- /**
- *@富文本实现图片自适应
- *@style再添加自适应样式
- */
- const html = res.replace(/<img[^>]*>/gi,function(match,capture){
- let match1 = match.replace(/<img*/gi, '<img style="width:100% !important;height:auto !important;float:left !important;"'),
- results = match1.replace(/style=/gi, 'style="width:100%;height:auto;float:left;"')
- return results
- })
- return html
- },
- formatDate:function(){
- //获取当前时间
- let date = new Date();
- let y = date.getFullYear();
- let MM = date.getMonth() + 1;
- MM = MM < 10 ? ('0' + MM) : MM;
- let d = date.getDate();
- d = d < 10 ? ('0' + d) : d;
- let h = date.getHours();
- h = h < 10 ? ('0' + h) : h;
- let m = date.getMinutes();
- m = m < 10 ? ('0' + m) : m;
- let s = date.getSeconds();
- s = s < 10 ? ('0' + s) : s;
- return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
- },
- }
- /**
- *@导出
- */
- module.exports = {
- formatDate: _Tools.formatDate,
- navigateTo: _Tools.navigateTo,
- redirectTo: _Tools.redirectTo,
- switchTabTo: _Tools.switchTabTo,
- setStorage: _Tools.setStorage,
- getStorage: _Tools.getStorage,
- getComStorage: _Tools.getComStorage,
- getWindowHeight: _Tools.getWindowHeight,
- adaptRichTextImg: _Tools.adaptRichTextImg,
- getStorageAddressKey: _Tools.getStorageAddressKey,
- }
|