From 4820b22cd1580b15ef69b634f800e3efce05e832 Mon Sep 17 00:00:00 2001 From: magic Date: Tue, 10 Sep 2024 17:08:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9B=BE=E7=89=87=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 18 ++++++++++++++++-- src/index.html | 4 ++++ src/lib/config.dev.js | 2 +- src/main.js | 43 ++++++++++++++++++++++++++++++------------- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4dbb1cc..c4e6fe2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "hydrogen-js-sdk", - "version": "2.4.1", + "version": "2.5.30", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "hydrogen-js-sdk", - "version": "2.4.1", + "version": "2.5.30", "license": "ISC", "dependencies": { "babel-runtime": "^6.26.0", + "eventsource-parser": "^1.0.0", "node.extend": "^2.0.0" }, "devDependencies": { @@ -3071,6 +3072,14 @@ "node": ">=0.8.0" } }, + "node_modules/eventsource-parser": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-1.1.2.tgz", + "integrity": "sha512-v0eOBUbiaFojBu2s2NPBfYUoRR9GjcDNvCXVaqEf5vVfpIAh9f8RCo4vXTP8c63QRKCFwoLpMpTdPwwhEKVgzA==", + "engines": { + "node": ">=14.18" + } + }, "node_modules/evp_bytestokey": { "version": "1.0.3", "resolved": "https://registry.npmmirror.com/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", @@ -11966,6 +11975,11 @@ "original": ">=0.0.5" } }, + "eventsource-parser": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-1.1.2.tgz", + "integrity": "sha512-v0eOBUbiaFojBu2s2NPBfYUoRR9GjcDNvCXVaqEf5vVfpIAh9f8RCo4vXTP8c63QRKCFwoLpMpTdPwwhEKVgzA==" + }, "evp_bytestokey": { "version": "1.0.3", "resolved": "https://registry.npmmirror.com/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", diff --git a/src/index.html b/src/index.html index 3ff1524..71f13dd 100644 --- a/src/index.html +++ b/src/index.html @@ -3,10 +3,14 @@ BmobSDK +
+
diff --git a/src/lib/config.dev.js b/src/lib/config.dev.js index 7890008..b7bc9c8 100644 --- a/src/lib/config.dev.js +++ b/src/lib/config.dev.js @@ -7,7 +7,7 @@ * @FilePath: /hydrogen-js-sdk/src/lib/config.dev.js */ // const ROOT = require('../../package.json') -// const HOST = "https://api.bmobcloud.com"; +const HOST = "https://api.bmobcloud.com"; // const HOST = 'http://127.0.0.1:8080' // const HOST = "https://apitest.bmob.cn"; // const HOST = 'http://website-restful.bmobapp.com' diff --git a/src/main.js b/src/main.js index 2b538f9..3418e59 100644 --- a/src/main.js +++ b/src/main.js @@ -66,19 +66,36 @@ console.log("aaa"); // let BmobSocketIo = Bmob.Socket(33) -// const fileUploadControl = document.getElementById('profilePhotoFileUpload'); -// fileUploadControl.onchange = () => { -// const pic = fileUploadControl.files -// let file -// for(let item of pic){ -// file = Bmob.File(item.name, item); -// } -// file.save().then(res => { -// const file = res[0] -// console.log(res.length); -// console.log(res,file); +// 获取文件上传控件元素 +const fileUploadControl = document.getElementById('profilePhotoFileUpload'); + +// 当文件选择发生变化时触发该事件处理函数 +fileUploadControl.onchange = () => { + // 获取选择的文件列表 + const pic = fileUploadControl.files; + + // 遍历选择的文件并创建Bmob.File对象 + for(let item of pic){ + // 初始化Bmob.File,命名文件并关联文件对象 + file = Bmob.File(item.name, item); + } + // 保存文件到云端存储服务 + file.save().then(res => { + // 保存成功后,获取保存结果 + const file = res[0]; + + // 打印保存文件的数量和文件信息 + console.log(res.length); + console.log(res,file,file.url); + + // file.url 插入到id为img的层下面最后一个元素图片展示 + document.getElementById('img').appendChild(document.createElement('img')).src = file.url; + + // 把文件url 文本插入到上一个图片后面 + document.getElementById('img').appendChild(document.createTextNode(file.url)); + -// }) -// } + }); +}