Merge pull request #16 from MooRoakee/main

修复了复制激活码页面会滚动到底部的问题
This commit is contained in:
NotoChen 2025-02-05 16:19:44 +08:00 committed by GitHub
commit 9e91cef62d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View File

@ -8,7 +8,7 @@ import org.springframework.boot.system.ApplicationHome;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.InputStream;
public interface FileTools { public interface FileTools {
@ -30,14 +30,14 @@ public interface FileTools {
File file = getFile(path); File file = getFile(path);
if (ObjectUtil.isNotNull(application.getSource())) { if (ObjectUtil.isNotNull(application.getSource())) {
ClassPathResource classPathResource = new ClassPathResource(path); ClassPathResource classPathResource = new ClassPathResource(path);
File classPathFile = FileUtil.file(classPathResource.getPath());
if (classPathResource.exists() && !file.exists()) { if (classPathResource.exists() && !file.exists()) {
try { try (InputStream inputStream = classPathResource.getInputStream()) {
FileUtil.writeFromStream(classPathResource.getInputStream(), classPathFile); FileUtil.writeFromStream(inputStream, file);
} catch (Exception e) { } catch (Exception e) {
throw new IllegalArgumentException(CharSequenceUtil.format("{} File read failed", classPathFile.getPath()), e); throw new IllegalArgumentException(
CharSequenceUtil.format("{} File read or write failed", path), e
);
} }
FileUtil.copy(classPathFile, file, true);
} }
} }
return file; return file;

View File

@ -74,16 +74,22 @@ $(document).ready(function() {
return navigator.clipboard.writeText(val); return navigator.clipboard.writeText(val);
} else { } else {
console.log(val); console.log(val);
const scrollX = window.scrollX;
const textArea = document.createElement('textarea') const textArea = document.createElement('textarea')
textArea.value = val textArea.value = val
// 使text area不在viewport同时设置不可见 // 使text area不在viewport同时设置不可见
document.body.appendChild(textArea) document.body.appendChild(textArea)
textArea.focus() textArea.focus()
textArea.select() textArea.select()
return new Promise((res, rej) => { try {
document.execCommand('copy') ? res() : rej() const result = document.execCommand('copy');
textArea.remove() return result ? Promise.resolve() : Promise.reject();
}) } catch (e) {
return Promise.reject(e);
} finally {
textArea.remove();
window.scrollTo(scrollX, 0);
}
} }
}; };