123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- //公共js,主要做表单验证,以及基本方法封装
- const utils = {
- isNullOrEmpty: function (value) {
- //是否为空
- return (value === null || value === '' || value === undefined) ? true : false;
- },
- trim: function (value) {
- //去空格
- return value.replace(/(^\s*)|(\s*$)/g, "");
- },
- isMobile: function (value) {
- //是否为手机号
- return /^(?:13\d|14\d|15\d|16\d|17\d|18\d|19\d)\d{5}(\d{3}|\*{3})$/.test(value);
- },
- isFloat: function (value) {
- //金额,只允许保留两位小数
- return /^([0-9]*[.]?[0-9])[0-9]{0,1}$/.test(value);
- },
- isNum: function (value) {
- //是否全为数字
- return /^[0-9]+$/.test(value);
- },
- formatNum: function (num) {
- //格式化手机号码
- if (utils.isMobile(num)) {
- num = num.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
- }
- return num;
- },
-
- interfaceUrl: function () {
- //接口地址
- return "https://automatapi.mengguohotel.com/";
- // return "http://127.0.0.1:8111/";
- },
- toast: function (text, duration, success) {
- wx.showToast({
- title: text,
- icon: success ? 'success' : 'none',
- duration: duration || 2000
- })
- },
- preventMultiple: function (fn, gapTime) {
- if (gapTime == null || gapTime == undefined) {
- gapTime = 200;
- }
- let lastTime = null;
- return function () {
- let now = +new Date();
- if (!lastTime || now - lastTime > gapTime) {
- fn.apply(this, arguments);
- lastTime = now;
- }
- }
- },
- request: function (url, postData, method, type, hideLoading,token) {
- //接口请求
- if (!hideLoading) {
- wx.showLoading({
- title: '请稍候...',
- mask: true
- })
- }
- return new Promise((resolve, reject) => {
- wx.request({
- url: this.interfaceUrl() + url,
- data: postData,
- header: {
- 'content-type': type ? 'application/x-www-form-urlencoded' : 'application/json',
- 'X-Access-Token': token ? token : ''
- },
- method: method, //'GET','POST'
- dataType: 'json',
- success: (res) => {
- !hideLoading && wx.hideLoading()
- if((res.statusCode && res.statusCode == 500) || (res.statusCode && res.statusCode == 401)){
- wx.reLaunch({
- url: '/pages/login/index',
- })
- }
- // if(res.statusCode && res.statusCode == 200 && res.data.message.indexOf('未获取到用户')>-1){
- // wx.reLaunch({
- // url: '/pages/login/index',
- // })
- // }
- resolve(res.data)
- },
- fail: (res) => {
- !hideLoading && this.toast("网络不给力,请稍后再试~")
- //wx.hideLoading()
- reject(res)
- }
- })
- })
- },
- uploadFile: function (src) {
- const that = this
- wx.showLoading({
- title: '请稍候...',
- mask: true
- })
- return new Promise((resolve, reject) => {
- const uploadTask = wx.uploadFile({
- url: 'http://39.108.124.252:8081/fileServce/file/ ', //测试地址,暂不使用
- filePath: src,
- name: 'file',
- header: {
- 'content-type': 'multipart/form-data'
- },
- formData: {},
- success: function (res) {
- wx.hideLoading()
- let d = JSON.parse(res.data)
- if (d.code === 1) {
- let fileObj = JSON.parse(d.data)[0];
- //文件上传成功后把图片路径数据提交到服务器,数据提交成功后,再进行下张图片的上传
- resolve(fileObj)
- } else {
- that.toast(res.message);
- }
- },
- fail: function (res) {
- reject(res)
- wx.hideLoading();
- that.toast(res.message);
- }
- })
- })
- },
- generateClientID: function () {
- var sessions = [];
- var clientID = '';
- var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- var numPossible = possible.length;
- do {
- for (var i = 0; i < 8; i++) {
- clientID += possible.charAt((Math.random() * numPossible) | 0);
- }
- } while (sessions['clientID'] != null);
- return clientID;
- },
- //timestamp 时间戳
- //option 格式(年月日 就输入YY-MM-DD 时分 就输入 hh-mm)
- //功能如下注释 ↓↓↓↓
- formatDate(timestamp, option) {
- var datatime= timestamp.replace(/\-/g, "/")
- var date = new Date(datatime);
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- var hour = function () {
- return date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
- }
- var minute = function () {
- return date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
- }
- var second = function () {
- return date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
- }
- //获取 年月日
- if (option == 'yyyy-MM-dd') return " " + year + "-" + month + "-" + day;
- //获取年月
- if (option == 'yyyy-MM') return " " + year + "-" + month;
- //获取年
- if (option == 'yyyy') return " " + year;
- //获取月
- if (option == 'MM') return " " + month;
- //获取日
- if (option == 'dd') return " " + day;
- //获取昨天
- if (option == 'yesterday') return " " + day - 1;
- //获取时分秒
- if (option == 'hh:mm:ss') return " " + hour() + ":" + minute() + ":" + second();
- //获取时分
- if (option == 'hh:mm') return " " + hour() + ":" + minute();
- //获取分秒
- if (option == 'mm:ss') return minute() + ":" + second();
- //获取分
- if (option == 'mm') return minute();
- //获取秒
- if (option == 'ss') return second();
- //默认时分秒年月日
- return year + '-' + month + '-' + day + ' ' + hour() + ':' + minute() + ":" + second();
- },
- api:{
- deviceListPage: 'api/device/deviceListPage',
- storeListPage: 'mgvm/mgVmStoreApi/storeListPage',
- queryByDeviceId: 'api/device/queryByDeviceId',
- storeList: 'mgvm/mgVmStoreApi/storeList',
- addDevice: 'api/device/addDevice',
- vmProductListPage: '/mgvm/mgVmProductApi/vmProductListPage',
- MgVmProductSkuPage:'/mgvm/mgVmProductSkuApi/list' ,
- productListPage: 'mgvm/mgSysProduct/sysProductListPage',
- queryByProductId: 'mgvm/mgSysProduct/queryByProductId',
- queryByVmProductId: 'mgvm/mgVmProductApi/queryByVmProductId',
- addVmProduct: 'mgvm/mgVmProductApi/addVmProduct',
- editVmProduct: 'mgvm/mgVmProductApi/editVmProduct',
- schemeListPage:'mgvm/mgVmSchemeApi/schemeListPage',
- schemeList:'mgvm/mgVmSchemeApi/schemeList',
- queryBySchemeId:'mgvm/mgVmSchemeApi/queryBySchemeId',
- addScheme:'mgvm/mgVmSchemeApi/addScheme',
- editScheme:'mgvm/mgVmSchemeApi/editScheme',
- orderListPage: 'mgvm/mgVmOrder/orderListPage',
- repairsListPage: 'mgvm/mgVmRepairs/repairsListPage',
- addRepairs: 'mgvm/mgVmRepairs/addRepairs',
- queryByStoreId: 'mgvm/mgVmStoreApi/queryByStoreId',
- addStore: 'mgvm/mgVmStoreApi/addStore',
- editStore: 'mgvm/mgVmStoreApi/editStore',
- stockDeviceList: 'api/device/stockDeviceList',
- upDevice:'api/device/upDeviceByStoreIdAnddevnceSn',
- productStockList: 'api/mgVmStoreProductSku/productStockList',
- editVmProductStock: 'api/mgVmStoreProductSku/editVmProductStock',
- addMerchantOrder: 'mgvm/mgSysProductOrder/addMerchantOrder',
- deviceListByStoreId: 'api/device/deviceListByStoreId',
- productOrderListPage: 'mgvm/mgSysProductOrder/productOrderListPage',
- queryByRepairsId: 'mgvm/mgVmRepairs/queryByRepairsId',
- storeList: 'mgvm/mgVmStoreApi/storeList',
- merchantLogin:'mgvm/miniLogin/merchantLogin',
- miniAppLogin:'mgvm/miniLogin/miniAppLogin',
- stockWarning: 'api/device/stockWarning',
- editMgVmDeviceGridProduct: 'api/device/editMgVmDeviceGridProduct',
- editMgVmDeviceGridProductQc: 'api/device/editMgVmDeviceGridProductQc',
- storeInfo: 'mgvm/mgVmStoreApi/storeInfo',
- getDeviceNum: 'api/device/getDeviceNum',
- getStockDeviceNum: 'api/device/getStockDeviceNum',
- changePassword: 'mgvm/info/changePassword',
- updateBankInfo:'mgvm/merchant/updateBankInfo',
- updateInfo:'mgvm/merchant/updateInfo',
- roleListPage: 'mgvm/info/roleListPage',
- addRole: 'mgvm/info/addRole',
- queryByUserId: 'mgvm/info/queryByUserId',
- editRole: 'mgvm/info/editRole',
- productOrderDetailPage:'mgvm/mgSysProductOrder/productOrderDetailPage',
- logout: 'mgvm/merchant/logout',
- withdrawMoney:'mgvm/withdrawMoneyApi/withdrawMoney',
- deleteMgVmProductById:'mgvm/mgVmProductApi/deleteMgVmProductById',
- deleteSchemeById:'mgvm/mgVmSchemeApi/deleteSchemeById',
- mgVmBillList:'mgvm/mgVmBill/list',
- unbundling:'api/device/unbundling',
- withdrawList:'mgvm/mgVmBill/withdrawList',
-
- indexSalesOrderApp:'mgvm/orderStatisApi/indexSalesOrderApp',
- salesOrderApp:'mgvm/orderStatisApi/salesOrderApp',
- storeDelete:'/mgvm/mgVmStoreApi/delete',
- agentList:'/mgvm/mgSysAgentApi/list',
- allAgentList:'/mgvm/mgSysAgentApi/agentList',
- agentAdd:'/mgvm/mgSysAgentApi/add',
- agentEdit:'/mgvm/mgSysAgentApi/edit',
- agentDelete:'/mgvm/mgSysAgentApi/delete',
- agentQueryById:'/mgvm/mgSysAgentApi/queryById',
- orderGoods: 'mgvm/mgVmProductSkuApi/orderGoods',
- reserve: 'mgvm/mgVmProductSkuApi/reserve',
- deviceTypeList:'/api/mgVmDeviceType/list',
- getDictByCode:'/api/sysDict/getDictByCode',
- replenishment: 'api/device/replenishment',
- mgVmStoreProductSkuList:'/api/mgVmStoreProductSku/list',
- childListByMtLei:'/sys/category/childListByMtLei',
- queryDetailListByOrderSn:'/mgvm/mgVmOrder/queryDetailListByOrderSn'
- },
- staticDomain:'https://mgvm.oss-cn-beijing.aliyuncs.com/',
- }
- module.exports = {
- isNullOrEmpty: utils.isNullOrEmpty,
- trim: utils.trim,
- isMobile: utils.isMobile,
- isFloat: utils.isFloat,
- isNum: utils.isNum,
- interfaceUrl: utils.interfaceUrl,
- toast: utils.toast,
- request: utils.request,
- uploadFile: utils.uploadFile,
- formatNum: utils.formatNum,
- generateClientID: utils.generateClientID,
- formatDate: utils.formatDate,
- api:utils.api,
- staticDomain: utils.staticDomain
- }
|