Przeglądaj źródła

Merge branch 'master' of http://git.jhcs888.com/zpj/zh-cashier-app

USER-20230908AJ\Administrator 1 rok temu
rodzic
commit
7d6094a6ac
5 zmienionych plików z 754 dodań i 0 usunięć
  1. 1 0
      App.vue
  2. 230 0
      common/css/common.css
  3. 65 0
      common/js/ajax.js
  4. 450 0
      common/js/tools.js
  5. 8 0
      pages/login.vue

+ 1 - 0
App.vue

@@ -14,4 +14,5 @@
 
 <style>
 	/*每个页面公共css */
+	@import "./common/css/common";
 </style>

+ 230 - 0
common/css/common.css

@@ -0,0 +1,230 @@
+
+image {
+  display: block;
+}
+
+/* 隐藏scroll-view 滚动条 */
+::-webkit-scrollbar {
+  display: none;
+}
+
+.iPhone-bottom {
+	padding-bottom: constant(safe-area-inset-bottom);
+	padding-bottom: env(safe-area-inset-bottom);
+}
+/* 不换行 */
+.view-nowrap{
+	white-space: nowrap;
+}
+/* 数字和文字不自动换行 */
+.overflowWrap{
+	overflowWrap:break-word;
+	word-break: break-all;
+}
+/* 自动换行 */
+.view-word-wrap{
+	white-space: pre-wrap;
+	word-wrap: break-word;
+}
+/*超出三行... */
+.text-overflow-ellipsis-t {
+	text-overflow: -o-ellipsis-lastline;
+	overflow: hidden;
+	text-overflow: ellipsis;
+	display: -webkit-box;
+	-webkit-line-clamp: 3;
+	line-clamp: 3;
+	-webkit-box-orient: vertical;
+	white-space: pre-wrap;
+	word-wrap: break-word;
+}
+
+/*超出两行... */
+.text-overflow-ellipsis {
+	text-overflow: -o-ellipsis-lastline;
+	overflow: hidden;
+	text-overflow: ellipsis;
+	display: -webkit-box;
+	-webkit-line-clamp: 2;
+	line-clamp: 2;
+	-webkit-box-orient: vertical;
+	white-space: pre-wrap;
+	word-wrap: break-word;
+}
+
+/*超出一行... */
+.text-overflow-ellipsis-one {
+	white-space: nowrap;
+	text-overflow: ellipsis;
+	overflow: hidden;
+	word-break: break-all;
+}
+/* 内部盒子 */
+.box-border-box{
+	box-sizing: border-box;
+}
+
+.flex-common-css {
+	width: 100%;
+	height: 100vh;
+	display: flex;
+	flex-direction: column;
+}
+.flex-index-css {
+	width: 100%;
+	height: 100%;
+	display: flex;
+	flex-direction: column;
+}
+.flex-direction-column {
+	display: flex;
+	flex-direction: column;
+}
+.display-flex {
+	display: flex;
+}
+.flex-justify-space {
+	display: flex;
+	justify-content: space-between;
+}
+
+.flex-justify-around {
+	display: flex;
+	justify-content: space-around;
+}
+
+.flex-justify-center {
+	display: flex;
+	justify-content: center;
+}
+.flex-justify-end {
+	display: flex;
+	justify-content: flex-end;
+}
+.flex-justify-start {
+	display: flex;
+	justify-content: flex-start;
+}
+.align-items-start {
+	display: flex;
+	align-items: flex-start;
+}
+.align-items-center {
+	display: flex;
+	align-items: center;
+}
+.align-items-flex-end {
+	display: flex;
+	align-items: flex-end;
+}
+.flex-wrap-wrap {
+	display: flex;
+	flex-wrap: wrap;
+}
+.common-view-css{
+	width: 100%;
+	flex: 1;
+}
+.scroll-view-css {
+	width: 100%;
+	flex: 1;
+	overflow: auto;
+}
+.box-sizing-border {
+	box-sizing: border-box;
+}
+.text-align-center {
+	text-align: center;
+}
+.text-align-right {
+	text-align: right;
+}
+.text-align-left {
+	text-align: left;
+}
+.flex-1{
+	flex: 1;
+}
+.flex-shrink0{
+	flex-shrink: 0;
+}
+
+/* 字体大小 */
+.fs-20{
+	font-size: 20rpx;
+}
+.fs-22{
+	font-size: 22rpx;
+}
+.fs-24{
+	font-size: 24rpx;
+}
+
+/* 字体粗细 */
+.fw-b{
+	font-weight: bold;
+}
+.fw-400{
+	font-weight: 400;
+}
+.fw-500{
+	font-weight: 500;
+}
+.fw-600{
+	font-weight: 600;
+}
+
+/* 字体颜色 */
+.fc-f{
+	color: #fff;
+}
+.fc-0{
+	color: #000;
+}
+.fc-3{
+	color: #333;
+}
+.fc-6{
+	color: #666;
+}
+.fc-9{
+	color: #999;
+}
+
+/* 背景颜色 */
+.bgc-f{
+	background-color: #fff;
+}
+.bgc-c{
+	background-color: #ccc;
+}
+.bgc-3{
+	background-color: #333;
+}
+.bgc-9{
+	background-color: #999;
+}
+
+
+
+
+/* 内边距 */
+
+.p-16{
+	padding: 16rpx;
+}
+.p-24{
+	padding: 24rpx;
+}
+.p-30{
+	padding: 30rpx;
+}
+.p-32{
+	padding: 32rpx;
+}
+
+/* 外边距 */
+.m-24{
+	margin: 24rpx;
+}
+

+ 65 - 0
common/js/ajax.js

@@ -0,0 +1,65 @@
+import tools from "@/service/tools";
+
+
+let BASE_URL =''
+
+//#ifndef H5
+BASE_URL ='https://' + process.uniEnv.baseUrl;
+//#endif
+
+
+
+export const request = (url, method, data, show = false) => {
+  let token = uni.getStorageSync('token')
+  let m_id = uni.getStorageSync('m_id')
+  if(token&&m_id){
+	  data.token = token;
+	  data.m_id = m_id
+  }
+  if (show) {
+    tools.showLoading();
+  }
+  if (data === undefined) {
+    data = {};
+  }
+  return new Promise((resolve, reject) => {
+    uni.request({
+      url:BASE_URL+  url,
+      data: data,
+      method: method || 'post',
+      header: {
+        'content-type': 'application/json',
+        'hversion': '1.0',
+        'Authorization': token
+      },
+      success: (res) => {
+        if (res.statusCode === 200) {
+          tools.hideLoading();
+          if (res.data.code * 1 === 401) {
+            uni.clearStorageSync()
+            uni.reLaunch({
+              url: '/pages/login'
+            });
+          } else {
+            resolve(res.data)
+          }
+        }else if(res.statusCode === 401){
+          window.localStorage.clear()
+          uni.clearStorageSync()
+          uni.reLaunch({
+            url: '/pages/login/index'
+          });
+        } else{
+          tools.error('网络错误!!')
+        }
+      },
+      fail: (err) => {
+        tools.error('网络错误!!')
+        reject(err)
+        tools.hideLoading();
+      }
+    })
+  })
+}
+
+

+ 450 - 0
common/js/tools.js

@@ -0,0 +1,450 @@
+
+let tools = {}
+/**
+ * 大小判断
+ * @param a
+ * @param b
+ * @returns {number}
+ */
+tools.sortNumber = function (a, b) {
+    return a - b;
+}
+
+tools.leftClick = function () {
+    let pages = getCurrentPages();
+	if(pages.length>1){
+        uni.navigateBack({
+            delta: 1
+        })
+    }else {
+        if(pages[pages.length -1].route.search("pages/finance") != -1){
+            uni.reLaunch({
+                url:"/pages/finance/index"
+            })
+        }else {
+            uni.switchTab({
+                url: '/pages/index/index'
+            });
+        }
+    }
+}
+
+tools.formatDateAgo = (dateStr)=> {
+  const now = new Date();
+  const target = new Date(dateStr);
+  const diff = (now - target) / 1000 / 60; // 转换为分钟
+
+  if (diff < 1) {
+    return '刚刚';
+  } else if (diff < 60) {
+    return parseInt(diff) + '分钟前';
+  } else if (diff < 60 * 24) {
+    return parseInt(diff / 60) + '小时前';
+  } else if (diff < 60 * 24 * 30) {
+    return parseInt(diff / 60 / 24) + '天前';
+  } else if (diff < 60 * 24 * 30 * 12) {
+    return parseInt(diff / 60 / 24 / 30) + '个月前';
+  } else {
+    return parseInt(diff / 60 / 24 / 30 / 12) + '年前';
+  }
+}
+
+
+tools.getTimeY = function(data) {
+    return new Date(data).getFullYear();
+}
+tools.getTimeM = function(data) {
+    let m = new Date(data).getMonth() + 1;
+    m = m>10?m:'0'+m
+    return m
+}
+tools.setTimeYM = function() {
+    let YM
+    let data = new Date()
+    let y =  tools.getTimeY(data)
+    let m =  tools.getTimeM(data)
+    return YM = `${y}-${m}`
+}
+
+/**
+ * 自定义 获取指定日期到当前日期的 所有年 or 年月
+ */
+tools.getCustomTimeList = (start,end,type)=>{
+    let timeList = [];
+    let s = start.split("-");
+    let e = end.split("-");
+    let min = new Date()
+    let max = new Date()
+    min.setFullYear(s[0], s[1]);
+    max.setFullYear(e[0], e[1]);
+    var curr = min;
+    var str = "";
+    while (curr <= max) {
+        var yers = curr.getFullYear();
+        var month = curr.getMonth();
+        if(type === 'y-m'){
+            if (month === 0) {
+                str = (yers - 1) + "-" + 12;
+            } else {
+                str = yers + "-" + (month < 10 ? ("0" + month) : month);
+            }
+            timeList.push(str);
+            curr.setMonth(month + 1);
+        }else if(type === 'y'){
+            if (month === 0) {
+                str = (yers - 1)
+            } else {
+                str = yers
+            }
+            timeList.push(str);
+            curr.setMonth(month + 1);
+        }else{}
+    }
+    if(type === 'y-m'){
+        return timeList.reverse()
+    }else{
+        let list = Array.from(new Set(timeList))
+        return list.reverse()
+    }
+}
+
+// 获取 当前 年-月 配合 getCustomTimeList 使用 获取end
+
+tools.getDateYM = ()=>{
+    let DATE = new Date()
+    let Y = DATE.getFullYear()
+    let M = DATE.getMonth() + 1
+    return Y + '-' + (M<10?'0'+M:M)
+}
+
+/**
+ * 保留两位小数
+ * @param num
+ * @returns {string}
+ */
+tools.twoFloating = function (num) {
+    // 获取两位小数
+    let price = "";
+    price = num * 1;
+    price = String(price).split(".")[1];
+    if (price !== undefined && price.length === 1) {
+        price = `.${price}0`;
+    } else {
+        price === undefined ? (price = ".00") : (price = `.${price}`);
+    }
+    return price;
+}
+tools.formatDecimal = function (num, decimal) {
+    num = num.toString()
+    let index = num.indexOf('.')
+    if (index !== -1) {
+        num = num.substring(0, decimal + index + 1)
+    } else {
+        num = num.substring(0)
+    }
+    return parseFloat(num).toFixed(decimal)
+}
+
+
+
+
+/**
+ * 错误提示
+ * @param msg
+ */
+tools.error = function (msg) {
+    uni.showToast({
+        'title': msg,
+        'icon': 'error',
+        'mask': true,
+        'duration': 1500
+    })
+}
+
+/**
+ * 成功提示
+ * @param msg
+ */
+tools.success = function (msg) {
+    uni.showToast({
+        'title': msg,
+        'icon': 'success',
+        'mask': true,
+        'duration': 1500
+    })
+}
+
+/**
+ * 显示Loading
+ */
+tools.showLoading = function () {
+    uni.showLoading({
+        title: '加载中...',
+        mask: true
+    });
+}
+
+/**
+ * 关闭Loading
+ */
+tools.hideLoading = function () {
+    uni.hideLoading();
+}
+
+/**
+ * 获取时间戳(毫秒)
+ * @returns {number}
+ */
+tools.getTime = function () {
+    return new Date().getTime();
+}
+
+
+tools.updateVersion = function (sysVersion, appUrl) {
+    let app_version = plus.runtime.version;
+    if (app_version < sysVersion) {
+        uni.showLoading({
+            title: '更新中……'
+        })
+        uni.downloadFile({//执行下载
+            url: appUrl, //下载地址
+            success: (downloadResult) => {//下载成功
+                uni.hideLoading();
+                if (downloadResult.statusCode === 200) {
+                    uni.showModal({
+                        title: '',
+                        content: '更新成功,确定现在重启吗?',
+                        confirmText: '重启',
+                        confirmColor: '#EE8F57',
+                        success: function (res) {
+                            if (res.confirm === true) {
+                                plus.runtime.install(//安装
+                                    downloadResult.tempFilePath, {
+                                    force: true
+                                },
+                                    function (res) {
+                                        tools.success('更新成功,重启中')
+                                        plus.runtime.restart();
+                                    }
+                                );
+                            }
+                        }
+                    });
+                }
+            }
+        });
+    } else {
+        // tools.success('你已是最新版本')
+    }
+}
+
+/**
+ * uniapp  html图片显示控制
+ * @param str
+ * @returns {*}
+ */
+tools.imgDeal = function (str) {
+    console.log(str)
+    if(str===null || str===undefined){
+        return '';
+    }else {
+        return str.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;"');
+    }
+
+}
+
+
+/**
+ * 获取平台类型  1:微信,2:支付宝
+ * @returns {boolean|number}
+ */
+tools.platformType = function () {
+    let ua = window.navigator.userAgent.toLowerCase();
+    if (ua.indexOf('micromessenger') != -1) {
+        return 1;
+    } else if (ua.indexOf('alipay') != -1) {
+        return 2;
+    } else {
+        return 0;
+    }
+}
+
+
+/**
+ * 获取开发平台
+ * @returns {string}
+ */
+tools.getPlatform = function () {
+    let platForm = undefined;
+    // #ifdef H5
+    platForm = 'H5';
+    //#endif
+    // #ifdef APP-PLUS
+    platForm = 'APP';
+    //#endif
+    // #ifdef APP-PLUS-NVUE
+    platForm = 'APP';
+    //#endif
+    // #ifdef APP-NVUE
+    platForm = 'APP';
+    //#endif
+    // #ifdef MP-WEIXIN
+    platForm = 'MP-WEIXIN'; // 小程序
+    //#endif
+    // #ifdef MP-ALIPAY
+    platForm = 'MP-ALIPAY';
+    //#endif
+    // #ifdef MP-BAIDU
+    platForm = 'MP-BAIDU';
+    //#endif
+    // #ifdef MP-TOUTIAO
+    platForm = 'MP-TOUTIAO';
+    //#endif
+    // #ifdef MP-LARK
+    platForm = 'MP-LARK';
+    //#endif
+    // #ifdef MP-QQ
+    platForm = 'MP-QQ';
+    //#endif
+    // #ifdef MP-KUAISHOU
+    platForm = 'MP-KUAISHOU';
+    //#endif
+    // #ifdef QUICKAPP-WEBVIEW
+    platForm = 'QUICKAPP-WEBVIEW';
+    //#endif
+    return platForm;
+
+}
+
+/**
+ * 记录用户登录信息
+ * @param data
+ * @param type
+ */
+tools.setLoginData = function (data) {
+    uni.setStorageSync('m_id', data.m_id)
+    uni.setStorageSync('token', data.token)
+    tools.success('登陆成功')
+    setTimeout(() => {
+        uni.switchTab({
+            url: '/pages/index/index'
+        });
+    }, 1500)
+
+}
+
+
+/**
+ * 微信JSDK授权
+ * @param jsApiList
+ * @returns {Promise<*>}
+ */
+tools.wxInitialize = async function (jsApiList) {
+    // #ifdef H5
+    return await getJsConfig({ 'url': window.location.href,'type':3 }).then((ret) => {
+        if (ret.code === 1) {
+            wxJs.config({
+                beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
+                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+                appId: ret.data.appId, // 必填,企业微信的corpID,必须是本企业的corpID,不允许跨企业使用
+                timestamp: ret.data.timestamp * 1, // 必填,生成签名的时间戳
+                nonceStr: ret.data.noncestr, // 必填,生成签名的随机串
+                signature: ret.data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
+                jsApiList: jsApiList,// 必填,需要使用的JS接口列表
+                success: function(res) {
+                    tools.success('成功')
+                },
+                fail: function(res) {}
+            });
+            return true;
+        } else {
+            return false;
+        }
+    })
+    //#endif
+
+}
+
+tools.weiXinPay = function (data) {
+    // #ifdef H5
+    return new Promise((resolve, reject) => {
+        wxJs.chooseWXPay({
+            appId: data.appId, // 必填,公众号的唯一标识
+            timestamp: data.timeStamp, // 支付签名时间戳,注意微信 jssdk 中的所有使用 timestamp 字段均为小写。但最新版的支付后台生成签名使用的 timeStamp 字段名需大写其中的 S 字符
+            nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
+            package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
+            signType: data.signType, // 微信支付V3的传入 RSA ,微信支付V2的传入格式与V2统一下单的签名格式保持一致
+            paySign: data.paySign, // 支付签名
+            success: function (res) {
+                resolve(true)
+            },
+            fail: function (res) {
+                resolve(false)
+            },
+        });
+    })
+    //#endif
+
+
+}
+
+
+/**
+ * 判定当前浏览器是否为微信浏览器
+ */
+tools.isWx = function () {
+    //#ifdef H5
+    let ua = window.navigator.userAgent.toLowerCase();
+    if (ua.indexOf('micromessenger') !== -1) {
+        return true;
+    } else {
+        return false;
+    }
+    //#endif
+	// #ifndef H5
+		return false;
+	// #endif
+}
+
+
+
+tools.wxLogin = function (urlPath) {
+    // #ifdef H5
+    // 微信浏览器
+    let url=window.location.href;
+    url = url.replace('&code=', '&code_a=1')
+    url = encodeURIComponent(url);
+
+    // let nodeEnv = process.env.NODE_ENV;
+    // let type = '';
+    // if(nodeEnv === 'development'){
+    // 	type = 2
+    // }else{
+    // 	type = 1
+    // }
+
+    window.location.href = `https://wx.jhcs888.com/#/?redirect_url=${Base64.encode(url)}&type=3`
+    //#endif
+
+}
+
+tools.setClipboardData=function (text){
+    uni.setClipboardData({
+        data: text,
+        success: function () {
+            tools.success('复制成功')
+        }
+    });
+}
+
+tools.download=function (url){
+    window.open(url)
+}
+
+
+tools.jyStart=function () {
+
+}
+
+
+export default tools

+ 8 - 0
pages/login.vue

@@ -0,0 +1,8 @@
+<template>
+</template>
+
+<script>
+</script>
+
+<style>
+</style>