github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/ui/src/api/utils.js (about) 1 import {config} from '../utils/vari' 2 import moment from 'moment'; 3 4 const PageSize = 15 5 const ResTypeDef = "def" 6 const ResTypeRanges = "ranges" 7 const ResTypeInstances = "instances" 8 const ResTypeConfig = "config" 9 export { PageSize, ResTypeDef, ResTypeRanges, ResTypeInstances, ResTypeConfig } 10 11 import {i18nRender} from '../locales' 12 13 export function checkLoop (rule, value, callback){ 14 console.log('checkLoop', value) 15 16 const regx1 = /^[1-9][0-9]*$/; 17 const regx2 = /^[1-9][0-9]*-?[1-9][0-9]*$/; 18 if (!regx1.test(value) && !regx2.test(value)) { 19 callback('需为整数或整数区间') 20 } 21 22 callback() 23 } 24 25 export function checkDirIsYaml (rule, value, callback){ 26 console.log('checkDirIsYaml', value) 27 28 if (value.indexOf('yaml/') != 0 && value.indexOf('yaml\\') != 0) { 29 callback(i18nRender('valid.folder.yaml')) 30 } 31 32 callback() 33 } 34 export function checkDirIsData (rule, value, callback){ 35 console.log('checkDirIsData', value) 36 37 if (value.indexOf('data/') != 0 && value.indexOf('data\\') != 0) { 38 callback(i18nRender('valid.folder.data')) 39 } 40 41 callback() 42 } 43 export function checkDirIsUsers (rule, value, callback){ 44 console.log('checkDirIsUsers', value) 45 46 if (value.indexOf('users/') != 0 && value.indexOf('users\\') != 0) { 47 callback(i18nRender('valid.folder.users')) 48 } 49 50 callback() 51 } 52 53 export function replacePathSep (path){ 54 const pth = path.replaceAll('\\', "/") 55 return pth 56 } 57 58 export function pathToRelated (path){ 59 if (!config.workDir) return '' 60 let name = path.substr(config.workDir.length) 61 name = replacePathSep(name) 62 return name 63 } 64 65 export function sectionStrToArr (str){ 66 str = str.substring(1, str.length - 1) 67 let arr = str.split(',') 68 str = arr.join('\n') 69 return str 70 } 71 72 export function formatTime (value){ 73 return moment(value).format('YYYY-MM-DD HH:mm:ss'); 74 } 75 76 export function trimChar (str, ch){ 77 if (str.substr(0, 1) != ch || str.substr(str.length - 1, 1) != ch) { 78 return str 79 } 80 81 if (str.indexOf(ch) == 0) { 82 str = str.substring(1) 83 } 84 85 if (str.indexOf(ch) == str.length - 1) { 86 str = str.substring(0, str.length - 1) 87 } 88 89 return str 90 }