import getConfig from 'next/config' import _ from 'lodash' export const getLocalApiPrefix = () => { const nextConfig = getConfig() const { publicRuntimeConfig } = nextConfig let { protocol, host, port } = publicRuntimeConfig if (typeof window !== 'undefined') { const location = window.location // console.log('location', location) protocol = location.protocol if (protocol.indexOf(':') !== -1) { protocol = protocol.split(':')[0] } host = location.hostname port = location.port } const localApiPrefix = protocol + '://' + host + ':' + port // console.log('localApiPrefix', localApiPrefix) return localApiPrefix } export const handleXSS = (content: string) => { content = content || '' return content.replace(//g, '>').replace(/\"/g, '"').replace(/\'/g, ''') } export const checkModalObj = (modalObj: {}, ignoreKeys: any = []) => { let result: any = null _.each(modalObj, (value: any, key: string) => { // console.log('checkModalObj', ignoreKeys, key, ignoreKeys.join('.').indexOf(key)) if (ignoreKeys.length === 0 || (ignoreKeys.length !== 0 && ignoreKeys.join('.').indexOf(key) === -1)) { if (_.trim(value) === '') { result = { key, reason: '不能为空' } return false } } }) return result }