HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/cms.smpolia.com/addons/uniapp/common/util.js
module.exports = {

	/**
	 * 跳转到指定小程序
	 * @param {string}  appId
	 * @param {string}  path
	 */
	navigateToMiniProgram(appId, path) {
		// #ifndef MP
		return;
		// #endif

		if (!appId || appId.length == 0) {
			return false
		}
		uni.navigateToMiniProgram({
			appId: appId,
			path: path,
			extraData: {},
			success(res) {}
		})
		return true
	},

	/**
	 * 三端复制插件
	 */
	uniCopy({
		content,
		success,
		error
	}) {
		content = typeof content === 'string' ? content : content.toString() // 复制内容,必须字符串,数字需要转换为字符串
		/**
		 * 小程序端 和 app端的复制逻辑
		 */
		//#ifndef H5
		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
	},

	/* 打开外部浏览器 */
	openBrowser(url) {
		// #ifdef MP-WEIXIN
		this.uniCopy(url)
		return;
		// #endif

		// #ifdef APP-PLUS
		plus.runtime.openURL(url);
		return;
		// #endif

		// #ifdef H5
		window.location.href = url;
		return;
		// #endif
	},
	/**
	 * link对象点击事件
	 * 支持tabBar页面
	 */
	openLink(linkObj) {
		if (!linkObj) return false
		// 跳转到指定页面
		switch (linkObj.type) {
			case 'Inlay':
			case 'Custom':
				uni.navigateTo({
					url: '/' + linkObj.path
				});
				break;
			case 'Location':
				uni.openLocation({
					latitude: parseFloat(linkObj.latitude),
					longitude: parseFloat(linkObj.longitude),
					name:linkObj.name,
					address:linkObj.address,
					success: function() {
						console.log('success');
					},
					fail: function(e) {
						console.log(e);
					},
				});
				break;
			case 'WXMp':
				this.navigateToMiniProgram(linkObj.appid, linkObj.path);
				break;
			case 'Outside':
				this.openBrowser(linkObj.url);
				break;
			case 'Phone':
				uni.makePhoneCall({
					phoneNumber: linkObj.phone
				})
				break;
			case 'Copy':
				this.uniCopy({
					content: linkObj.text,
					success: (res) => {
						uni.showToast({
							title: res,
							icon: 'none'
						})
					},
					error: (e) => {
						uni.showToast({
							title: e,
							icon: 'none',
							duration: 3000,
						})
					}
				});
				break;
			default:
				break;
		}
		return true
	}
}