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 java.io.File;
import java.io.IOException;
import java.io.InputStream;
public interface FileTools {
@ -30,14 +30,14 @@ public interface FileTools {
File file = getFile(path);
if (ObjectUtil.isNotNull(application.getSource())) {
ClassPathResource classPathResource = new ClassPathResource(path);
File classPathFile = FileUtil.file(classPathResource.getPath());
if (classPathResource.exists() && !file.exists()) {
try {
FileUtil.writeFromStream(classPathResource.getInputStream(), classPathFile);
try (InputStream inputStream = classPathResource.getInputStream()) {
FileUtil.writeFromStream(inputStream, file);
} 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;

View File

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