import * as Lodash from 'lodash-uni'
import dayjs from 'dayjs'
import { loadModule } from 'vue3-sfc-loader'
const loadModuleOptions = {
moduleCache: {
'lodash-uni': Lodash,
'dayjs': dayjs
},
async getFile(url) {
const packageUrl = url.replace('.mjs', '.js')
const { resourcesUrl } = JSON.parse(localStorage.getItem('CDN_CONFIG'))
const baseUrl = resourcesUrl.slice(0, resourcesUrl.lastIndexOf('/'))
const fullUrl = `${baseUrl}${packageUrl}`
const res = await fetch(fullUrl)
if (!res.ok) throw new Error(res.statusText)
return {
getContentData: (asBinary) => (asBinary ? res.arrayBuffer() : res.text())
}
},
addStyle: () => {}
}
const loadCodeFunction = async (packageName, packageUrl) => {
try {
const module = await loadModule(packageUrl.replace('.js', '.mjs'), loadModuleOptions)
setCodeFunctions(packageName, module)
} catch (e) {
console.error('initCodeFunctions error', e)
}
}
// 遠(yuǎn)程js文件內(nèi)容
import dayjs from "dayjs"
import {
isNumber,
toNumber,
sum
} from 'lodash-uni'
// 僅支持使用以上2個依賴提供的方法
function fn1(a, b) {
console.log(dayjs('2020-02-02 12:00:00').format('YYYY-MM-DD'))
console.log('isNumber', isNumber('1.234')
return a / b
}
function fn2(a, b) {
console.log(isNumber(1111))
return a * b
}
function sumArray(array) {
return sum(array)
}
export { // 請使用相同的導(dǎo)出方式看政,不要加default
fn1,
fn2,
sumArray
}