123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import store from '@/store'
- import {stringIsBlank} from "@/utils/blank-utils";
- import {xcMessage} from "@/utils/xiaochan-element-plus";
- export function needRule(...val) {
- const userRoles = store.state.user.info.roles
- if (userRoles.includes(1)) {
- return true;
- }
- for (let i = 0; i < val.length; i++) {
- if (userRoles.includes(val[i])) {
- return true;
- }
- }
- return false;
- }
- export function noNeedRule(...val) {
- return !needRule(val)
- }
- export let isDev = import.meta.env.VITE_BASE_URL !== 'http://172.16.32.160:8077'
- export const nullToEmpty = (val) => {
- if (stringIsBlank(val)) {
- return ''
- } else {
- return val
- }
- }
- export const elementAddBody = (val) => {
- const body = document.querySelector("body");
- if (body.append) {
- body.append(val);
- } else {
- body.appendChild(val);
- }
- }
- /**
- * 对比版本号
- * @param version1 版本1
- * @param version2 版本 2
- * @returns {number} 1 大于 -1小于 0等于
- */
- export function compareVersion(version1, version2) {
- const arr1 = version1.split('.')
- const arr2 = version2.split('.')
- const length1 = arr1.length
- const length2 = arr2.length
- const minlength = Math.min(length1, length2)
- let i = 0
- for (i; i < minlength; i++) {
- let a = parseInt(arr1[i])
- let b = parseInt(arr2[i])
- if (a > b) {
- return 1
- } else if (a < b) {
- return -1
- }
- }
- if (length1 > length2) {
- for (let j = i; j < length1; j++) {
- if (parseInt(arr1[j]) !== 0) {
- return 1
- }
- }
- return 0
- } else if (length1 < length2) {
- for (let j = i; j < length2; j++) {
- if (parseInt(arr2[j]) !== 0) {
- return -1
- }
- }
- return 0
- }
- return 0
- }
- export const chineseEncrypt = {
- encrypt: (val) => {
- if (stringIsBlank(val)) {
- return "";
- }
- return encodeURI(JSON.stringify(val))
- },
- decrypt: (val) => {
- if (stringIsBlank(val)) {
- return "";
- }
- return JSON.parse(decodeURI(val))
- }
- }
- export const copyStrFunc = (val) => {
- let input = document.createElement('input')
- document.body.appendChild(input);
- input.value = val;
- input.select();
- document.execCommand("copy");
- document.body.removeChild(input);
- xcMessage.success("复制成功。")
- }
- // 判断字符串是否包含中文
- export const isChinese = (str) => {
- return /[\u4e00-\u9fa5]/.test(str);
- }
- // 判断字符串是否为纯英文
- export const isEnglish = (str) => {
- return /^[a-zA-Z]+$/.test(str);
- }
|