更新记录
1.0.1(2023-08-22) 下载此版本
优化SDK路径
1.0.0(2023-08-21) 下载此版本
基础功能
平台兼容性
Vue2 | Vue3 |
---|---|
√ | × |
App | 快应用 | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 |
---|---|---|---|---|---|---|
app-vue | × | √ | × | × | × | × |
钉钉小程序 | 快手小程序 | 飞书小程序 | 京东小程序 |
---|---|---|---|
× | × | × | × |
H5-Safari | Android Browser | 微信浏览器(Android) | QQ浏览器(Android) | Chrome | IE | Edge | Firefox | PC-Safari |
---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | × | × | × |
引用插件
main.js 中引入插件并设置全局变量:
import ResourceManager from "js_sdk/king-resource-manager/king-resource-manage.js"
Vue.prototype.$ResourceMgr=ResourceManager
插件初始化
App.vue 中 onLaunch 中进行初始化
//加载本地JSON,建议开放阶段使用本地JSON进行调试
this.$ResourceMgr.setConfig(require("@/static/resourceConfig.json"))
//加载Json文件,域名得在小程序中配置
this.$ResourceMgr.setConfig("https://.../config/resourceConfig.json")
//API获取配置文件
this.$ResourceMgr.setGetConfigFunc(this.getConfig)
//async获取配置文件,并return配置信息
async getConfig() {
const res = await uniCloud.callFunction({
name: 'resource',
data: {
active: "getResrouceConfig",
flag: "Dello"
}
})
const result = res.result
if (result.code == 200) {
console.log("-----",result.data.config)
return result.data.config
}else{
return {}
}
},
插件使用
单个获取单个文件:
this.picUrl = await this.$ResourceMgr.getResource('pic6', this.showLoading)
多个文件:
const fileList = []
fileList.push('pic1')
fileList.push('pic2')
fileList.push('pic3')
fileList.push('pic4')
const res = await this.$ResourceMgr.getResourceList(fileList, this.showLoading)
console.log("本地素材资源路径", res)
this.picList = res
资源配置文件,通过修改version进行素材更新
{
"pic1": {
"des": "",
"url": "https://p0.ssl.img.360kuai.com/t01462aec786b689e69.jpg?size=1920x1080",
"version": 1,
"downloaded": false
},
"pic2": {
"des": "",
"url": "https://p0.ssl.img.360kuai.com/t013aebc42fa4f326b1.jpg?size=1200x676",
"version": 1,
"downloaded": false
},
"pic3": {
"des": "",
"url": "https://p0.ssl.img.360kuai.com/t01ab6f424961928ab8.jpg?size=1334x602",
"version": 1,
"downloaded": false
},
"pic4": {
"des": "",
"url": "http://p7.itc.cn/images01/20201001/501434b4b09a4500bad79cb401572fc5.jpeg",
"version": 1,
"downloaded": false
},
"pic5": {
"des": "",
"url": "http://p5.itc.cn/images01/20201001/1d2f9c31c63d4153b222a6c31e520215.jpeg",
"version": 1,
"downloaded": false
},
"pic6": {
"des": "",
"url": "https://img0.baidu.com/it/u=3499375362,128129564&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800",
"version": 1,
"downloaded": false
}
}
创作不易,求打赏杯咖啡,希望后续能创作更多实用插件