|
@@ -3,105 +3,8 @@
|
|
|
* @Author Zhengjingyi
|
|
|
* @Action 全局公共方法
|
|
|
*/
|
|
|
-import requestUrl from '@/services/ajax.env.js'
|
|
|
-const caimeiApi = {
|
|
|
- /**
|
|
|
- * @封装公共get数据请求方法无加载动画
|
|
|
- * @方法参数:请求地址,请求后台需要的参数字段,回调函数
|
|
|
- * @自定义请求头信息
|
|
|
- */
|
|
|
- get:function(url,data,callback){
|
|
|
- uni.request({
|
|
|
- url: requestUrl + url,
|
|
|
- data:data,
|
|
|
- header: {
|
|
|
- 'Accept': 'application/json',
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
- 'X-Token': uni.getStorageSync('token') ? uni.getStorageSync('token') : 'token',
|
|
|
- 'cookie': uni.getStorageSync('sessionid')
|
|
|
- },
|
|
|
- method: 'GET',
|
|
|
- success: (response) => {
|
|
|
- if(response.statusCode !== 200){
|
|
|
- uni.showToast({icon: 'none',title:'服务器连接错误',duration: 2000})
|
|
|
- callback(response.statusCode)
|
|
|
- }else{
|
|
|
- callback(response.data)
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (error) => {
|
|
|
- if (error) {
|
|
|
- uni.showToast({icon: 'none',title: '网络错误,请稍后重试',duration: 2000})
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- /**
|
|
|
- * @封装公共get数据请求方法有加载动画
|
|
|
- * @方法参数:请求地址,请求后台需要的参数字段,回调函数
|
|
|
- * @自定义请求头信息
|
|
|
- */
|
|
|
- lodingGet:function(url,data,callback){
|
|
|
- uni.showLoading({mask: true,title:'加载中~',})
|
|
|
- uni.request({
|
|
|
- url: requestUrl + url,
|
|
|
- data:data,
|
|
|
- header: {
|
|
|
- 'Accept': 'application/json',
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
- 'X-Token': uni.getStorageSync('token') ? uni.getStorageSync('token') : 'token',
|
|
|
- 'cookie': uni.getStorageSync('sessionid')
|
|
|
- },
|
|
|
- method: 'GET',
|
|
|
- success: (response) => {
|
|
|
- if(response.statusCode !== 200){
|
|
|
- uni.showToast({icon: 'none',title: '服务器连接错误',duration: 2000})
|
|
|
- callback(response.statusCode)
|
|
|
- }else{
|
|
|
- callback(response.data)
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (error) => {
|
|
|
- if (error) {
|
|
|
- uni.showToast({icon: 'none',title: '网络错误,请稍后重试',duration: 2000})
|
|
|
- }
|
|
|
- },
|
|
|
- complete: () => {
|
|
|
- setTimeout(function () {
|
|
|
- uni.hideLoading()
|
|
|
- }, 250)
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- /**
|
|
|
- * @封装公共post数据请求方法
|
|
|
- * @方法参数:请求地址,请求后台需要的参数字段,回调函数
|
|
|
- */
|
|
|
- post:function(url,data,loadingStatus,callback){
|
|
|
- if(loadingStatus){uni.showLoading({mask: true,title:'加载中~'})}
|
|
|
- uni.request({
|
|
|
- url: requestUrl+url,
|
|
|
- data:data,
|
|
|
- header: {
|
|
|
- 'Accept': 'application/json',
|
|
|
- // 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- },
|
|
|
- method: 'POST',
|
|
|
- success: (response) => {
|
|
|
- console.log(response)
|
|
|
- if(loadingStatus){uni.hideLoading()}
|
|
|
- const result = response.data
|
|
|
- callback(result)
|
|
|
- },
|
|
|
- fail: (error) => {
|
|
|
- uni.hideLoading()
|
|
|
- if (error) {
|
|
|
- uni.showToast({icon: 'none',title: '网络错误,请稍后重试',duration: 2000})
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
+import requestUrl from '@/services/config.env.js'
|
|
|
+const _Tools = {
|
|
|
getComStorage:function(key){// 获取本地Storage
|
|
|
return new Promise(function(resolve,reject) {
|
|
|
uni.getStorage({
|
|
@@ -148,135 +51,6 @@ const caimeiApi = {
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
- loginStatus:function(){
|
|
|
- // 获取用户是否登陆 1:已登陆,否则未登陆
|
|
|
- return new Promise(function(resolve,reject) {
|
|
|
- uni.getStorage({
|
|
|
- key: 'userInfo',
|
|
|
- success: function (res){
|
|
|
- if(res.data.code == '1'){
|
|
|
- resolve(true)
|
|
|
- } else {
|
|
|
- resolve(false)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- navToListPage:function({type,value,id,lType} = {}){
|
|
|
- // 跳转到列表页
|
|
|
- if(lType=='4'){
|
|
|
- const pages = getCurrentPages()
|
|
|
- const prevPage = pages[pages.length-2]
|
|
|
- prevPage.refresh = true
|
|
|
- prevPage.listData = {
|
|
|
- type: type,
|
|
|
- from: value,
|
|
|
- id: id
|
|
|
- }
|
|
|
- uni.navigateBack({
|
|
|
- delta: 1
|
|
|
- })
|
|
|
- }else{
|
|
|
- uni.navigateTo({
|
|
|
- url:`/pages/goods/goods?type=${type}&from=${value}&id=${id}`
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- navigateToGoods:function({type,value,id,lType} = {}){
|
|
|
- // 跳转到列表页
|
|
|
- if(lType=='4'){
|
|
|
- const pages = getCurrentPages()
|
|
|
- const prevPage = pages[pages.length-2]
|
|
|
- prevPage.refresh = true
|
|
|
- prevPage.listData = {
|
|
|
- type: type,
|
|
|
- from: value,
|
|
|
- id: id
|
|
|
- }
|
|
|
- uni.navigateBack({
|
|
|
- delta: 1
|
|
|
- })
|
|
|
- }else{
|
|
|
- uni.navigateTo({
|
|
|
- url:`/pages/goods/goods-classify?type=${type}&from=${value}&id=${id}`
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- FlooryNavigateTo:function(pros){
|
|
|
- if(pros.listType == 1){
|
|
|
- if(pros.product.productCategory == '1'){
|
|
|
- uni.navigateTo({
|
|
|
- url:`/pages/goods/product?id=${pros.product.productID}`
|
|
|
- })
|
|
|
- }else{
|
|
|
- uni.navigateTo({
|
|
|
- url:`/second/pages/product/product-details?id=${pros.product.productID}`
|
|
|
- })
|
|
|
- }
|
|
|
- }else{
|
|
|
- /**
|
|
|
- * 页面跳转类型
|
|
|
- * 1、二级页面,2、搜索项目仪器,3、直播页面,4、自由页面,5、商品详情,6、仪器项目详情,7、供应商主页
|
|
|
- * 8、专题活动页,9、二手市场介绍,10、二手商品列表,11、二手商品发布,12、商品搜索,13、信息详情
|
|
|
- * 14、品牌招商介绍页,15、维修保养介绍页,16、首页,17、注册页,18、信息中心,19、供应商列表
|
|
|
- **/
|
|
|
- if(pros.linkType){
|
|
|
- console.log(pros.linkType)
|
|
|
- const typeMap = {
|
|
|
- 1:`/pages/goods/goods-instrument?linkId=${pros.linkParam.id}`,
|
|
|
- 2:`/pages/goods/instrument-details?id=${pros.linkParam.id}`,
|
|
|
- 4:`/h5/pages/activity/activity?title=${pros.crmTitle}&link=${pros.crmLink}`,
|
|
|
- 5:`/pages/goods/product?id=${pros.linkParam.id}`,
|
|
|
- 7:`/supplier/pages/user/my-shop?shopId=${pros.linkParam.id}`,
|
|
|
- 8:'/h5/pages/activity/activity-list',
|
|
|
- 9:'/second/pages/form/introduce',
|
|
|
- 10:'/second/pages/product/product-list',
|
|
|
- 11:'/second/pages/form/form',
|
|
|
- 12:`/search/pages/search/search?keyWord=${pros.linkParam.keyword}`,
|
|
|
- 13:`/h5/pages/article/path?link=${pros.link}`,
|
|
|
- 14:`/h5/pages/article/path?link=${pros.link}`,
|
|
|
- 15:`/h5/pages/article/path?link=${pros.link}`,
|
|
|
- 17:'/pages/login/register-select',
|
|
|
- 18:`/h5/pages/article/path?link=${pros.link}`,
|
|
|
- 19:`/search/pages/search/search-supplier?keyWord=${pros.linkParam.keyword}`,
|
|
|
- 21:'/h5/pages/activity/meobohui'
|
|
|
-
|
|
|
- }
|
|
|
- const url = typeMap[pros.linkType]
|
|
|
- uni.navigateTo({
|
|
|
- url:url
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- BannerNavigateTo:function(linkType,linkId,linkHref,keyword){//楼层跳转判断
|
|
|
- if(linkType){
|
|
|
- const typeMap = {
|
|
|
- 1:`/pages/goods/goods-instrument?linkId=${linkId}`,
|
|
|
- 2:`/pages/goods/instrument-details?id=${linkId}`,
|
|
|
- 4:`/h5/pages/activity/activity?id=${linkId}`,
|
|
|
- 5:`/pages/goods/product?id=${linkId}`,
|
|
|
- 7:`/supplier/pages/user/my-shop?shopId=${linkId}`,
|
|
|
- 8:'/h5/pages/activity/activity-list',
|
|
|
- 9:'/second/pages/form/introduce',
|
|
|
- 10:'/second/pages/product/product-list',
|
|
|
- 11:'/second/pages/form/form',
|
|
|
- 12:`/search/pages/search/search?keyWord=${keyword}`,
|
|
|
- 13:`/h5/pages/article/path?link=${linkHref}`,
|
|
|
- 14:`/h5/pages/article/path?link=${linkHref}`,
|
|
|
- 15:`/h5/pages/article/path?link=${linkHref}`,
|
|
|
- 17:'/pages/login/register-select',
|
|
|
- 18:`/h5/pages/article/path?link=${linkHref}`,
|
|
|
- 19:`/search/pages/search/search-supplier?keyWord=${keyword}`,
|
|
|
- 21:'/h5/pages/activity/meobohui'
|
|
|
- }
|
|
|
- const url = typeMap[linkType]
|
|
|
- uni.navigateTo({
|
|
|
- url:url
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
navigateTo:function(url){
|
|
|
//路由跳转:页面之间路由跳转
|
|
|
uni.navigateTo({
|
|
@@ -295,14 +69,6 @@ const caimeiApi = {
|
|
|
url:url
|
|
|
})
|
|
|
},
|
|
|
- isNumber:function(value){//验证是否为数字
|
|
|
- var patrn = /^(-)?\d+(\.\d+)?$/
|
|
|
- if (patrn.exec(value) == null || value == '') {
|
|
|
- return false
|
|
|
- } else {
|
|
|
- return true
|
|
|
- }
|
|
|
- },
|
|
|
getWindowHeight:function(){
|
|
|
// 获取窗口高度
|
|
|
const {windowHeight, pixelRatio} = wx.getSystemInfoSync()
|
|
@@ -320,76 +86,36 @@ const caimeiApi = {
|
|
|
})
|
|
|
return html
|
|
|
},
|
|
|
- FormatMoney:function(num){
|
|
|
- // 金额千分位
|
|
|
- return num.toString().replace(/\d+/, function (n) { // 先提取整数部分
|
|
|
- return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { // 对整数部分添加分隔符
|
|
|
- return $1 + ','
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
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
|
|
|
- },
|
|
|
- regexSets:function() {
|
|
|
- let sets = {
|
|
|
- 'companyName': /^[\u4e00-\u9fa5\(\)()\s\da-zA-Z&]{2,50}$/gi,
|
|
|
- 'phoneAndTelephone': /^([1]\d{10}|([\((]?0[0-9]{2,3}[)\)]?[-]?)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?)$/,
|
|
|
- 'bankNum': /^([1-9]{1})(\d{18})$/,
|
|
|
- 'invalidChar': /^[\s\u4e00-\u9fa5a-z0-9_-]{0,}$/
|
|
|
- }
|
|
|
- return sets
|
|
|
+ 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;
|
|
|
},
|
|
|
- timestampToTime:function(timestamp) {
|
|
|
- // 时间戳转日期
|
|
|
- let date = new Date(timestamp * 1000)//时间戳为10位需*1000,时间戳为13位的话不需乘1000
|
|
|
- let Y = date.getFullYear() + '-'
|
|
|
- let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
|
|
|
- let D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' '
|
|
|
- let h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':'
|
|
|
- let m = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':'
|
|
|
- let s = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds())
|
|
|
- return `${Y}${M}${D}${h}${m}${s}`
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*@导出
|
|
|
*/
|
|
|
module.exports = {
|
|
|
- get: caimeiApi.get,
|
|
|
- post: caimeiApi.post,
|
|
|
- lodingGet: caimeiApi.lodingGet,
|
|
|
- isNumber: caimeiApi.isNumber,
|
|
|
- FormatMoney: caimeiApi.FormatMoney,
|
|
|
- navigateTo: caimeiApi.navigateTo,
|
|
|
- redirectTo: caimeiApi.redirectTo,
|
|
|
- switchTabTo: caimeiApi.switchTabTo,
|
|
|
- formatDate: caimeiApi.formatDate,
|
|
|
- loginStatus: caimeiApi.loginStatus,
|
|
|
- setStorage: caimeiApi.setStorage,
|
|
|
- getStorage: caimeiApi.getStorage,
|
|
|
- getComStorage: caimeiApi.getComStorage,
|
|
|
- navToListPage: caimeiApi.navToListPage,
|
|
|
- navigateToGoods: caimeiApi.navigateToGoods,
|
|
|
- getWindowHeight: caimeiApi.getWindowHeight,
|
|
|
- adaptRichTextImg: caimeiApi.adaptRichTextImg,
|
|
|
- getStorageAddressKey: caimeiApi.getStorageAddressKey,
|
|
|
- regexSets: caimeiApi.regexSets,
|
|
|
- timestampToTime: caimeiApi.timestampToTime,
|
|
|
- BannerNavigateTo:caimeiApi.BannerNavigateTo,
|
|
|
- FlooryNavigateTo:caimeiApi.FlooryNavigateTo
|
|
|
+ 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,
|
|
|
}
|