123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- export default {
- /**
- * 参数处理
- * @param params 参数
- */
- tansParams(params) {
- let result = "";
- for (const propName of Object.keys(params)) {
- const value = params[propName];
- var part = encodeURIComponent(propName) + "=";
- if (value !== null && value !== "" && typeof value !== "undefined") {
- if (typeof value === "object") {
- for (const key of Object.keys(value)) {
- if (value[key] !== null && value[key] !== "" && typeof value[key] !== "undefined") {
- let params = propName + "[" + key + "]";
- var subPart = encodeURIComponent(params) + "=";
- result += subPart + encodeURIComponent(value[key]) + "&";
- }
- }
- } else {
- result += part + encodeURIComponent(value) + "&";
- }
- }
- }
- return result;
- },
- /**
- * @一键拨号
- */
- makePhoneCall(phone) {
- uni.makePhoneCall({
- phoneNumber: phone,
- success: function () {
- console.log('success');
- },
- fail: function () {
- }
- });
- },
- /**
- * @复制粘贴板
- * @param {传入值} content
- * @returns
- */
- uniCopy({ content, success, error }) {
- if (!content) return error('复制的内容不能为空 !')
- content = typeof content === 'string' ? content : content.toString() // 复制内容,必须字符串,数字需要转换为字符串
- /**
- * 小程序端 和 app端的复制逻辑
- */
- //#ifdef APP-PLUS || MP-WEIXIN
- uni.setClipboardData({
- data: content,
- success: function () {
- success("复制成功~")
- console.log('success');
- },
- fail: function () {
- success("复制失败~")
- }
- });
- //#endif
- /**
- * H5端的复制逻辑
- */
- // #ifdef H5
- if (!document.queryCommandSupported('copy')) { //为了兼容有些浏览器 queryCommandSupported 的判断
- // 不支持
- error('浏览器不支持')
- }
- let textarea = document.createElement("textarea")
- textarea.value = content
- textarea.readOnly = "readOnly"
- document.body.appendChild(textarea)
- textarea.select() // 选择对象
- textarea.setSelectionRange(0, content.length) //核心
- let result = document.execCommand("copy") // 执行浏览器复制命令
- if (result) {
- success("复制成功~")
- } else {
- error("复制失败,请检查h5中调用该方法的方式,是不是用户点击的方式调用的,如果不是请改为用户点击的方式触发该方法,因为h5中安全性,不能js直接调用!")
- }
- textarea.remove()
- // #endif
- },
- /**
- * @param {时间处理(今日,昨日)}
- * @param {传入值} time
- * @returns
- */
- jktTimes(time) {
- if (time == undefined) return "";
- var today = new Date().getDate();//当前时间-日
- var day = new Date(time).getDate();//传入时间-日
- var newday = today - day
- if (newday == 0) {
- var newTime = time.split(" ")[1]
- var newTime2 = newTime.split(":")
- return "今天" + newTime2[0] + ":" + newTime2[1];
- } else if (newday == 1) {
- var newTime = time.split(" ")[1]
- var newTime2 = newTime.split(":")
- return "昨天" + newTime2[0] + ":" + newTime2[1];
- } else {
- var newTime = time.split(" ")[0]
- return newTime
- }
- },
- /**
- * @指定获取开始时间结束时间
- */
- getDays(value) {
- let oneDay = 24 * 60 * 60 * 1000;
- let endTime = new Date(Date.now());
- endTime = this.formatterDate(endTime, "yyyy-MM-dd");
- let startTime = new Date(Date.now() - value * oneDay);
- startTime = this.formatterDate(startTime, "yyyy-MM-dd");
- const days = [startTime, endTime,]
- return days;
- },
- /**
- * @处理公共日期格式
- */
- formatterDate(date, fmt) {
- let nowDate = {
- yyyy: date.getFullYear(), // 年
- MM: date.getMonth() + 1, // 月份
- dd: date.getDate(), //日
- hh: date.getHours(),
- mm: date.getMinutes(),
- ss: date.getSeconds(),
- };
- if (/(y+)/.test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
- }
- for (var k in nowDate) {
- if (new RegExp("(" + k + ")").test(fmt)) {
- fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? nowDate[k] : ("00" + nowDate[k]).substr(("" + nowDate[k]).length));
- }
- }
- return fmt;
- },
- };
|