123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import pinia from "@/store/init"
- import {useAppStore} from "@/store";
- const store = useAppStore(pinia)
- import {getObjVal, isNullES} from "js-fast-way";
- // 按钮权限
- export const btnAuth = async (auth = '') => {
- if(isNullES(auth)) auth = 'all'
- try {
- let isDownload = false, isPrint = false;
- //下载权限
- const pdfDownload = store.getButtonsVal('client-pdf-download')
- isDownload = !!getObjVal(pdfDownload)
- //打印权限
- const pdfPrint = store.getButtonsVal('client-pdf-print')
- isPrint = !!getObjVal(pdfPrint)
- //判断权限
- if(auth == 'all') {
- return isDownload && isPrint
- } else if(auth == 'download') {
- return isDownload
- } else if(auth == 'print') {
- return isPrint
- }
- } catch {
- return false
- }
- }
- //确认框
- export const showModal = async ({title, content, confirmText, cancelText}) => {
- return new Promise((resolve) => {
- uni.showModal({
- title: title,
- content: content,
- confirmText: confirmText ?? '确定',
- cancelText: cancelText ?? '取消',
- success: function (res) {
- if (res.confirm) {
- resolve(true)
- } else if (res.cancel) {
- resolve(false)
- }
- }
- });
- })
- }
- //成功提示
- export const successToast = (title = '成功', duration= 2000) => {
- uni.showToast({
- title: title,
- duration: duration,
- mask: true
- });
- }
- //失败提示
- export const errorToast = (title = '失败', duration= 1500) => {
- uni.showToast({
- title: title,
- duration: duration,
- icon: 'none'
- });
- }
- //获取元素信息
- export const querySelect = async (_this, name) => {
- return new Promise((resolve) => {
- const query = uni.createSelectorQuery().in(_this);
- query.select(`#${name}`).boundingClientRect(data => {
- resolve(data)
- }).exec();
- })
- }
- //表单验证
- export const formValidate = async (formRef) => {
- return new Promise( (resolve) => {
- formRef.validate().then((res) => {
- resolve(true)
- }).catch(err => {
- resolve(false)
- })
- });
- }
- //pdf文件预览
- export const toPdfPreview = async (url) => {
- const isAuth = await btnAuth()
- // #ifdef H5
- window.open(url, '_blank')
- // #endif
- // #ifdef APP-PLUS
- if(isAuth) {
- const res = await showModal({
- title: '提示',
- content: '请选择一种预览pdf的方式',
- confirmText: '系统级预览',
- cancelText: '应用内预览',
- })
- if (res) {
- openDocFile(url)
- } else {
- uni.navigateTo({
- url: '/pages/index/preview?url=' + encodeURIComponent(url)
- });
- }
- } else {
- uni.navigateTo({
- url: '/pages/index/preview?url=' + encodeURIComponent(url)
- });
- }
- // #endif
- }
- //预览文件
- export const openDocFile = (url, fileType='pdf') => {
- uni.showLoading({title: '加载中...', mask: true})
- uni.downloadFile({
- url: url,
- success: function (res) {
- uni.openDocument({
- filePath: res.tempFilePath,
- fileType: fileType,
- showMenu: true,
- })
- },
- complete: function () {
- uni.hideLoading()
- }
- });
- }
|