mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-04-29 11:36:45 +00:00
Compare commits
11 Commits
release/5.
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ea1d7468a | ||
|
|
4cf19d1dbe | ||
|
|
3abf864184 | ||
|
|
634babfba4 | ||
|
|
e7fe1afe19 | ||
|
|
cd2abb4be1 | ||
|
|
dd803126dd | ||
|
|
633e47b765 | ||
|
|
c52d80c123 | ||
|
|
ee2a27501b | ||
|
|
171762d676 |
@@ -1,6 +1,5 @@
|
|||||||
package cn.keking.config;
|
package cn.keking.config;
|
||||||
|
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.redisson.Redisson;
|
import org.redisson.Redisson;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
@@ -13,8 +12,8 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redisson 客户端配置
|
* Redisson 客户端配置(完善版)
|
||||||
* Created by kl on 2017/09/26.
|
* 支持 single / cluster / master-slave / sentinel 四种模式,配置完整,统一参数。
|
||||||
*/
|
*/
|
||||||
@ConditionalOnExpression("'${cache.type:default}'.equals('redis')")
|
@ConditionalOnExpression("'${cache.type:default}'.equals('redis')")
|
||||||
@ConfigurationProperties(prefix = "spring.redisson")
|
@ConfigurationProperties(prefix = "spring.redisson")
|
||||||
@@ -22,114 +21,71 @@ import org.springframework.util.ClassUtils;
|
|||||||
public class RedissonConfig {
|
public class RedissonConfig {
|
||||||
|
|
||||||
// ========================== 连接配置 ==========================
|
// ========================== 连接配置 ==========================
|
||||||
private static String address;
|
private String address;
|
||||||
private static String password;
|
private String password;
|
||||||
private static String clientName;
|
private String clientName;
|
||||||
private static int database = 0;
|
private int database = 0;
|
||||||
private static String mode = "single";
|
private String mode = "single";
|
||||||
private static String masterName = "kkfile";
|
private String masterName = "kkfile";
|
||||||
|
|
||||||
// ========================== 超时配置 ==========================
|
// ========================== 超时配置 ==========================
|
||||||
private static int idleConnectionTimeout = 10000;
|
private int idleConnectionTimeout = 10000;
|
||||||
private static int connectTimeout = 10000;
|
private int connectTimeout = 10000;
|
||||||
private static int timeout = 3000;
|
private int timeout = 3000;
|
||||||
|
|
||||||
// ========================== 重试配置 ==========================
|
// ========================== 重试配置 ==========================
|
||||||
private static int retryAttempts = 3;
|
private int retryAttempts = 3;
|
||||||
private static int retryInterval = 1500;
|
private int retryInterval = 1500;
|
||||||
|
|
||||||
// ========================== 连接池配置 ==========================
|
// ========================== 连接池配置 ==========================
|
||||||
private static int connectionMinimumIdleSize = 10;
|
private int connectionMinimumIdleSize = 10;
|
||||||
private static int connectionPoolSize = 64;
|
private int connectionPoolSize = 64;
|
||||||
private static int subscriptionsPerConnection = 5;
|
private int subscriptionsPerConnection = 5;
|
||||||
private static int subscriptionConnectionMinimumIdleSize = 1;
|
private int subscriptionConnectionMinimumIdleSize = 1;
|
||||||
private static int subscriptionConnectionPoolSize = 50;
|
private int subscriptionConnectionPoolSize = 50;
|
||||||
|
|
||||||
|
// ========================== 集群专用配置 ==========================
|
||||||
|
private int scanInterval = 2000;
|
||||||
|
|
||||||
// ========================== 其他配置 ==========================
|
// ========================== 其他配置 ==========================
|
||||||
private static int dnsMonitoringInterval = 5000;
|
private int dnsMonitoringInterval = 5000;
|
||||||
private static int thread; // 当前处理核数量 * 2
|
private int threads; // 默认为0,表示使用 CPU 核数 * 2
|
||||||
private static String codec = "org.redisson.codec.JsonJacksonCodec";
|
private String codec = "org.redisson.codec.JsonJacksonCodec";
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public static RedissonClient config() throws Exception {
|
public RedissonClient redissonClient() {
|
||||||
Config config = new Config();
|
Config config = new Config();
|
||||||
|
|
||||||
// 密码处理
|
// 密码处理:空字符串转为 null
|
||||||
if (StringUtils.isBlank(password)) {
|
String pwd = StringUtils.isBlank(password) ? null : password;
|
||||||
password = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据模式创建对应的 Redisson 配置
|
// 根据模式构建配置
|
||||||
switch (mode) {
|
switch (mode.toLowerCase()) {
|
||||||
case "cluster":
|
case "cluster":
|
||||||
configureClusterMode(config);
|
configureClusterMode(config, pwd);
|
||||||
break;
|
break;
|
||||||
case "master-slave":
|
case "master-slave":
|
||||||
configureMasterSlaveMode(config);
|
configureMasterSlaveMode(config, pwd);
|
||||||
break;
|
break;
|
||||||
case "sentinel":
|
case "sentinel":
|
||||||
configureSentinelMode(config);
|
configureSentinelMode(config, pwd);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
configureSingleMode(config);
|
configureSingleMode(config, pwd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 公共配置:编码器、线程数
|
||||||
|
applyCommonConfig(config);
|
||||||
return Redisson.create(config);
|
return Redisson.create(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================== 配置方法 ==========================
|
// ========================== 配置方法 ==========================
|
||||||
|
|
||||||
/**
|
private void configureSingleMode(Config config, String pwd) {
|
||||||
* 配置集群模式
|
String normalizedAddress = normalizeAddress(address);
|
||||||
*/
|
|
||||||
private static void configureClusterMode(Config config) {
|
|
||||||
String[] clusterAddresses = address.split(",");
|
|
||||||
config.useClusterServers()
|
|
||||||
.setScanInterval(2000)
|
|
||||||
.addNodeAddress(clusterAddresses)
|
|
||||||
.setPassword(password)
|
|
||||||
.setRetryAttempts(retryAttempts)
|
|
||||||
.setTimeout(timeout)
|
|
||||||
.setMasterConnectionPoolSize(100)
|
|
||||||
.setSlaveConnectionPoolSize(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置主从模式
|
|
||||||
*/
|
|
||||||
private static void configureMasterSlaveMode(Config config) {
|
|
||||||
String[] masterSlaveAddresses = address.split(",");
|
|
||||||
validateMasterSlaveAddresses(masterSlaveAddresses);
|
|
||||||
|
|
||||||
String[] slaveAddresses = new String[masterSlaveAddresses.length - 1];
|
|
||||||
System.arraycopy(masterSlaveAddresses, 1, slaveAddresses, 0, slaveAddresses.length);
|
|
||||||
|
|
||||||
config.useMasterSlaveServers()
|
|
||||||
.setDatabase(database)
|
|
||||||
.setPassword(password)
|
|
||||||
.setMasterAddress(masterSlaveAddresses[0])
|
|
||||||
.addSlaveAddress(slaveAddresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置哨兵模式
|
|
||||||
*/
|
|
||||||
private static void configureSentinelMode(Config config) {
|
|
||||||
String[] sentinelAddresses = address.split(",");
|
|
||||||
config.useSentinelServers()
|
|
||||||
.setDatabase(database)
|
|
||||||
.setPassword(password)
|
|
||||||
.setMasterName(masterName)
|
|
||||||
.addSentinelAddress(sentinelAddresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置单机模式
|
|
||||||
*/
|
|
||||||
private static void configureSingleMode(Config config) throws Exception {
|
|
||||||
config.useSingleServer()
|
config.useSingleServer()
|
||||||
.setAddress(address)
|
.setAddress(normalizedAddress)
|
||||||
.setConnectionMinimumIdleSize(connectionMinimumIdleSize)
|
.setConnectionMinimumIdleSize(connectionMinimumIdleSize)
|
||||||
.setConnectionPoolSize(connectionPoolSize)
|
.setConnectionPoolSize(connectionPoolSize)
|
||||||
.setDatabase(database)
|
.setDatabase(database)
|
||||||
@@ -143,183 +99,184 @@ public class RedissonConfig {
|
|||||||
.setTimeout(timeout)
|
.setTimeout(timeout)
|
||||||
.setConnectTimeout(connectTimeout)
|
.setConnectTimeout(connectTimeout)
|
||||||
.setIdleConnectionTimeout(idleConnectionTimeout)
|
.setIdleConnectionTimeout(idleConnectionTimeout)
|
||||||
.setPassword(StringUtils.trimToNull(password));
|
.setPassword(pwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureClusterMode(Config config, String pwd) {
|
||||||
|
String[] nodeAddresses = normalizeAddresses(address.split(","));
|
||||||
|
config.useClusterServers()
|
||||||
|
.setScanInterval(scanInterval)
|
||||||
|
.addNodeAddress(nodeAddresses)
|
||||||
|
.setPassword(pwd)
|
||||||
|
.setRetryAttempts(retryAttempts)
|
||||||
|
.setRetryInterval(retryInterval)
|
||||||
|
.setTimeout(timeout)
|
||||||
|
.setConnectTimeout(connectTimeout)
|
||||||
|
.setIdleConnectionTimeout(idleConnectionTimeout)
|
||||||
|
.setMasterConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSlaveConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize)
|
||||||
|
.setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize)
|
||||||
|
.setSubscriptionsPerConnection(subscriptionsPerConnection)
|
||||||
|
.setClientName(clientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureMasterSlaveMode(Config config, String pwd) {
|
||||||
|
String[] addresses = address.split(",");
|
||||||
|
validateMasterSlaveAddresses(addresses);
|
||||||
|
String[] normalizedAddresses = normalizeAddresses(addresses);
|
||||||
|
String masterAddress = normalizedAddresses[0];
|
||||||
|
String[] slaveAddresses = new String[normalizedAddresses.length - 1];
|
||||||
|
System.arraycopy(normalizedAddresses, 1, slaveAddresses, 0, slaveAddresses.length);
|
||||||
|
|
||||||
|
config.useMasterSlaveServers()
|
||||||
|
.setDatabase(database)
|
||||||
|
.setPassword(pwd)
|
||||||
|
.setMasterAddress(masterAddress)
|
||||||
|
.addSlaveAddress(slaveAddresses)
|
||||||
|
.setRetryAttempts(retryAttempts)
|
||||||
|
.setRetryInterval(retryInterval)
|
||||||
|
.setTimeout(timeout)
|
||||||
|
.setConnectTimeout(connectTimeout)
|
||||||
|
.setIdleConnectionTimeout(idleConnectionTimeout)
|
||||||
|
.setMasterConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSlaveConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize)
|
||||||
|
.setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize)
|
||||||
|
.setSubscriptionsPerConnection(subscriptionsPerConnection)
|
||||||
|
.setClientName(clientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureSentinelMode(Config config, String pwd) {
|
||||||
|
String[] sentinelAddresses = normalizeAddresses(address.split(","));
|
||||||
|
config.useSentinelServers()
|
||||||
|
.setDatabase(database)
|
||||||
|
.setPassword(pwd)
|
||||||
|
.setMasterName(masterName)
|
||||||
|
.addSentinelAddress(sentinelAddresses)
|
||||||
|
.setRetryAttempts(retryAttempts)
|
||||||
|
.setRetryInterval(retryInterval)
|
||||||
|
.setTimeout(timeout)
|
||||||
|
.setConnectTimeout(connectTimeout)
|
||||||
|
.setIdleConnectionTimeout(idleConnectionTimeout)
|
||||||
|
.setMasterConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSlaveConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize)
|
||||||
|
.setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize)
|
||||||
|
.setSubscriptionsPerConnection(subscriptionsPerConnection)
|
||||||
|
.setClientName(clientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCommonConfig(Config config) {
|
||||||
// 设置编码器
|
// 设置编码器
|
||||||
Class<?> codecClass = ClassUtils.forName(getCodec(), ClassUtils.getDefaultClassLoader());
|
if (StringUtils.isNotBlank(codec)) {
|
||||||
|
try {
|
||||||
|
Class<?> codecClass = ClassUtils.forName(codec, ClassUtils.getDefaultClassLoader());
|
||||||
Codec codecInstance = (Codec) codecClass.getDeclaredConstructor().newInstance();
|
Codec codecInstance = (Codec) codecClass.getDeclaredConstructor().newInstance();
|
||||||
config.setCodec(codecInstance);
|
config.setCodec(codecInstance);
|
||||||
// 设置线程和事件循环组
|
} catch (Exception e) {
|
||||||
config.setThreads(thread);
|
throw new IllegalStateException("Failed to create Redisson codec: " + codec, e);
|
||||||
config.setEventLoopGroup(new NioEventLoopGroup());
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// 设置线程数(大于0时生效,否则Redisson使用默认值:CPU核数*2)
|
||||||
|
if (threads > 0) {
|
||||||
|
config.setThreads(threads);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================== 辅助方法 ==========================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证主从模式地址
|
* 自动补齐 Redis 地址协议前缀(redis:// 或 rediss://)
|
||||||
*/
|
*/
|
||||||
private static void validateMasterSlaveAddresses(String[] addresses) {
|
private String normalizeAddress(String addr) {
|
||||||
if (addresses.length == 1) {
|
if (addr == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
addr = addr.trim();
|
||||||
|
if (!addr.startsWith("redis://") && !addr.startsWith("rediss://")) {
|
||||||
|
addr = "redis://" + addr;
|
||||||
|
}
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] normalizeAddresses(String[] addresses) {
|
||||||
|
String[] normalized = new String[addresses.length];
|
||||||
|
for (int i = 0; i < addresses.length; i++) {
|
||||||
|
normalized[i] = normalizeAddress(addresses[i]);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateMasterSlaveAddresses(String[] addresses) {
|
||||||
|
if (addresses.length < 2) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"redis.redisson.address MUST have multiple redis addresses for master-slave mode.");
|
"Master-slave mode requires at least 2 addresses: master and at least one slave. " +
|
||||||
|
"Current addresses: " + String.join(",", addresses));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================== Getter和Setter方法 ==========================
|
// ========================== Getter / Setter(供 Spring 绑定配置) ==========================
|
||||||
|
// 以下所有字段都需要提供 getter/setter,示例中只列出关键字段,实际使用时请补全所有字段。
|
||||||
|
// 建议使用 Lombok @Data 或 IDE 自动生成。这里只展示部分,避免篇幅过长。
|
||||||
|
|
||||||
// 连接配置
|
public String getAddress() { return address; }
|
||||||
public String getAddress() {
|
public void setAddress(String address) { this.address = address; }
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAddress(String address) {
|
public String getPassword() { return password; }
|
||||||
RedissonConfig.address = address;
|
public void setPassword(String password) { this.password = password; }
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
public String getClientName() { return clientName; }
|
||||||
return password;
|
public void setClientName(String clientName) { this.clientName = clientName; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public int getDatabase() { return database; }
|
||||||
RedissonConfig.password = password;
|
public void setDatabase(int database) { this.database = database; }
|
||||||
}
|
|
||||||
|
|
||||||
public String getClientName() {
|
public String getMode() { return mode; }
|
||||||
return clientName;
|
public void setMode(String mode) { this.mode = mode; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setClientName(String clientName) {
|
public String getMasterName() { return masterName; }
|
||||||
RedissonConfig.clientName = clientName;
|
public void setMasterName(String masterName) { this.masterName = masterName; }
|
||||||
}
|
|
||||||
|
|
||||||
public int getDatabase() {
|
public int getIdleConnectionTimeout() { return idleConnectionTimeout; }
|
||||||
return database;
|
public void setIdleConnectionTimeout(int idleConnectionTimeout) { this.idleConnectionTimeout = idleConnectionTimeout; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setDatabase(int database) {
|
public int getConnectTimeout() { return connectTimeout; }
|
||||||
RedissonConfig.database = database;
|
public void setConnectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; }
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMode() {
|
public int getTimeout() { return timeout; }
|
||||||
return mode;
|
public void setTimeout(int timeout) { this.timeout = timeout; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setMode(String mode) {
|
public int getRetryAttempts() { return retryAttempts; }
|
||||||
RedissonConfig.mode = mode;
|
public void setRetryAttempts(int retryAttempts) { this.retryAttempts = retryAttempts; }
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMasterNamee() {
|
public int getRetryInterval() { return retryInterval; }
|
||||||
return masterName;
|
public void setRetryInterval(int retryInterval) { this.retryInterval = retryInterval; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setMasterNamee(String masterName) {
|
public int getConnectionMinimumIdleSize() { return connectionMinimumIdleSize; }
|
||||||
RedissonConfig.masterName = masterName;
|
public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) { this.connectionMinimumIdleSize = connectionMinimumIdleSize; }
|
||||||
}
|
|
||||||
|
|
||||||
// 超时配置
|
public int getConnectionPoolSize() { return connectionPoolSize; }
|
||||||
public int getIdleConnectionTimeout() {
|
public void setConnectionPoolSize(int connectionPoolSize) { this.connectionPoolSize = connectionPoolSize; }
|
||||||
return idleConnectionTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdleConnectionTimeout(int idleConnectionTimeout) {
|
public int getSubscriptionsPerConnection() { return subscriptionsPerConnection; }
|
||||||
RedissonConfig.idleConnectionTimeout = idleConnectionTimeout;
|
public void setSubscriptionsPerConnection(int subscriptionsPerConnection) { this.subscriptionsPerConnection = subscriptionsPerConnection; }
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectTimeout() {
|
public int getSubscriptionConnectionMinimumIdleSize() { return subscriptionConnectionMinimumIdleSize; }
|
||||||
return connectTimeout;
|
public void setSubscriptionConnectionMinimumIdleSize(int subscriptionConnectionMinimumIdleSize) { this.subscriptionConnectionMinimumIdleSize = subscriptionConnectionMinimumIdleSize; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectTimeout(int connectTimeout) {
|
public int getSubscriptionConnectionPoolSize() { return subscriptionConnectionPoolSize; }
|
||||||
RedissonConfig.connectTimeout = connectTimeout;
|
public void setSubscriptionConnectionPoolSize(int subscriptionConnectionPoolSize) { this.subscriptionConnectionPoolSize = subscriptionConnectionPoolSize; }
|
||||||
}
|
|
||||||
|
|
||||||
public int getTimeout() {
|
public int getScanInterval() { return scanInterval; }
|
||||||
return timeout;
|
public void setScanInterval(int scanInterval) { this.scanInterval = scanInterval; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeout(int timeout) {
|
public int getDnsMonitoringInterval() { return dnsMonitoringInterval; }
|
||||||
RedissonConfig.timeout = timeout;
|
public void setDnsMonitoringInterval(int dnsMonitoringInterval) { this.dnsMonitoringInterval = dnsMonitoringInterval; }
|
||||||
}
|
|
||||||
|
|
||||||
// 重试配置
|
public int getThreads() { return threads; }
|
||||||
public int getRetryAttempts() {
|
public void setThreads(int threads) { this.threads = threads; }
|
||||||
return retryAttempts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRetryAttempts(int retryAttempts) {
|
public String getCodec() { return codec; }
|
||||||
RedissonConfig.retryAttempts = retryAttempts;
|
public void setCodec(String codec) { this.codec = codec; }
|
||||||
}
|
|
||||||
|
|
||||||
public int getRetryInterval() {
|
|
||||||
return retryInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRetryInterval(int retryInterval) {
|
|
||||||
RedissonConfig.retryInterval = retryInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 连接池配置
|
|
||||||
public int getConnectionMinimumIdleSize() {
|
|
||||||
return connectionMinimumIdleSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) {
|
|
||||||
RedissonConfig.connectionMinimumIdleSize = connectionMinimumIdleSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionPoolSize() {
|
|
||||||
return connectionPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectionPoolSize(int connectionPoolSize) {
|
|
||||||
RedissonConfig.connectionPoolSize = connectionPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSubscriptionsPerConnection() {
|
|
||||||
return subscriptionsPerConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubscriptionsPerConnection(int subscriptionsPerConnection) {
|
|
||||||
RedissonConfig.subscriptionsPerConnection = subscriptionsPerConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSubscriptionConnectionMinimumIdleSize() {
|
|
||||||
return subscriptionConnectionMinimumIdleSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubscriptionConnectionMinimumIdleSize(int subscriptionConnectionMinimumIdleSize) {
|
|
||||||
RedissonConfig.subscriptionConnectionMinimumIdleSize = subscriptionConnectionMinimumIdleSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSubscriptionConnectionPoolSize() {
|
|
||||||
return subscriptionConnectionPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubscriptionConnectionPoolSize(int subscriptionConnectionPoolSize) {
|
|
||||||
RedissonConfig.subscriptionConnectionPoolSize = subscriptionConnectionPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 其他配置
|
|
||||||
public int getDnsMonitoringInterval() {
|
|
||||||
return dnsMonitoringInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDnsMonitoringInterval(int dnsMonitoringInterval) {
|
|
||||||
RedissonConfig.dnsMonitoringInterval = dnsMonitoringInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getThread() {
|
|
||||||
return thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setThread(int thread) {
|
|
||||||
RedissonConfig.thread = thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getCodec() {
|
|
||||||
return codec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCodec(String codec) {
|
|
||||||
RedissonConfig.codec = codec;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
package cn.keking.service.cache.impl;
|
package cn.keking.service.cache.impl;
|
||||||
|
|
||||||
import cn.keking.service.cache.CacheService;
|
import cn.keking.service.cache.CacheService;
|
||||||
import org.redisson.Redisson;
|
|
||||||
import org.redisson.api.RBlockingQueue;
|
import org.redisson.api.RBlockingQueue;
|
||||||
import org.redisson.api.RMapCache;
|
import org.redisson.api.RMapCache;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
import org.redisson.config.Config;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -23,8 +21,9 @@ public class CacheServiceRedisImpl implements CacheService {
|
|||||||
|
|
||||||
private final RedissonClient redissonClient;
|
private final RedissonClient redissonClient;
|
||||||
|
|
||||||
public CacheServiceRedisImpl(Config config) {
|
// 直接注入 Spring 容器中的 RedissonClient Bean
|
||||||
this.redissonClient = Redisson.create(config);
|
public CacheServiceRedisImpl(RedissonClient redissonClient) {
|
||||||
|
this.redissonClient = redissonClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
|
|
||||||
function isNotEmpty(value) {
|
|
||||||
return value !== null && value !== undefined && value !== '' && value !== 'false' ;
|
|
||||||
}
|
|
||||||
|
|
||||||
function watermarkObj(watermarkContainer,watermarkTxt) {
|
|
||||||
try {
|
|
||||||
if (!isNotEmpty(watermarkTxt)) {
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
var watermarkSettings = {
|
|
||||||
watermark_txt: watermarkTxt,
|
|
||||||
watermark_start_x:80,//水印起始位置x轴坐标
|
|
||||||
watermark_start_y:80,//水印起始位置Y轴坐标
|
|
||||||
watermark_x_space:80,//水印x轴间隔
|
|
||||||
watermark_y_space:80,//水印y轴间隔
|
|
||||||
watermark_color:'black',//水印字体颜色
|
|
||||||
watermark_alpha:0.2,//水印透明度
|
|
||||||
watermark_fontsize:'18px',//水印字体大小
|
|
||||||
watermark_font:'微软雅黑',//水印字体
|
|
||||||
watermark_width:200,//水印宽度
|
|
||||||
watermark_height:80,//水印高度
|
|
||||||
watermark_angle:30//水印倾斜度数
|
|
||||||
};
|
|
||||||
// console.log(watermarkContainer);
|
|
||||||
var page_width = $(watermarkContainer).width() - watermarkSettings.watermark_width;
|
|
||||||
var page_height = $(watermarkContainer).height() - watermarkSettings.watermark_height;
|
|
||||||
page_width = (page_width < 250) ? 250 : page_width;
|
|
||||||
page_height = (page_height < 250) ? 250 : page_height;
|
|
||||||
var oTemp = document.createDocumentFragment();
|
|
||||||
for (var x = watermarkSettings.watermark_start_x; x < page_width; x+= watermarkSettings.watermark_x_space) {
|
|
||||||
for (var y = watermarkSettings.watermark_start_y; y < page_height; y+= watermarkSettings.watermark_y_space) {
|
|
||||||
var mask_div = document.createElement('div');
|
|
||||||
// mask_div.id = 'mask_div' + x + y;
|
|
||||||
mask_div.className = 'mask_div';
|
|
||||||
mask_div.appendChild(document.createTextNode(watermarkTxt));
|
|
||||||
// 设置水印div倾斜显示
|
|
||||||
mask_div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+(watermarkSettings.watermark_alpha*100)+")";
|
|
||||||
mask_div.style.webkitTransform = "rotate(-" + watermarkSettings.watermark_angle + "deg)";
|
|
||||||
mask_div.style.MozTransform = "rotate(-" + watermarkSettings.watermark_angle + "deg)";
|
|
||||||
mask_div.style.msTransform = "rotate(-" + watermarkSettings.watermark_angle + "deg)";
|
|
||||||
mask_div.style.OTransform = "rotate(-" + watermarkSettings.watermark_angle + "deg)";
|
|
||||||
mask_div.style.transform = "rotate(-" + watermarkSettings.watermark_angle + "deg)";
|
|
||||||
mask_div.style.visibility = "";
|
|
||||||
mask_div.style.position = "absolute";
|
|
||||||
mask_div.style.left = x + 'px';
|
|
||||||
mask_div.style.top = y + 'px';
|
|
||||||
mask_div.style.overflow = "hidden";
|
|
||||||
mask_div.style.zIndex = "100";
|
|
||||||
mask_div.style.pointerEvents='none';//pointer-events:none 让水印不遮挡页面的点击事件
|
|
||||||
//mask_div.style.border="solid #eee 1px";
|
|
||||||
mask_div.style.opacity = watermarkSettings.watermark_alpha;
|
|
||||||
mask_div.style.fontSize = watermarkSettings.watermark_fontsize;
|
|
||||||
mask_div.style.fontFamily = watermarkSettings.watermark_font;
|
|
||||||
mask_div.style.color = watermarkSettings.watermark_color;
|
|
||||||
mask_div.style.textAlign = "center";
|
|
||||||
mask_div.style.width = watermarkSettings.watermark_width + 'px';
|
|
||||||
mask_div.style.height = watermarkSettings.watermark_height + 'px';
|
|
||||||
mask_div.style.display = "block";
|
|
||||||
oTemp.appendChild(mask_div);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$(watermarkContainer).append(oTemp);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1221,8 +1221,6 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
<!-- editorUndoBar -->
|
<!-- editorUndoBar -->
|
||||||
</div>
|
</div>
|
||||||
<!-- outerContainer -->
|
<!-- outerContainer -->
|
||||||
<script type="text/javascript" src="/js/jquery-3.6.1.min.js"></script>
|
|
||||||
<script type="text/javascript" src="/js/pdfwatermark.js"></script>
|
|
||||||
<div id="printContainer"></div>
|
<div id="printContainer"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -9,6 +9,83 @@ if (kkpdfAutoFetch == "true") {
|
|||||||
} else {
|
} else {
|
||||||
kkpdfAutoFetch = false
|
kkpdfAutoFetch = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isNotEmpty(value) {
|
||||||
|
return value !== null && value !== undefined && value !== '' && value !== 'false' ;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 通用水印生成函数
|
||||||
|
* @param {HTMLElement} container - 水印容器(相对定位的父元素)
|
||||||
|
* @param {string} watermarkTxt - 水印文字
|
||||||
|
* @param {number} [explicitWidth] - 可选:显式指定容器宽度(px),不传则自动获取
|
||||||
|
* @param {number} [explicitHeight] - 可选:显式指定容器高度(px),不传则自动获取
|
||||||
|
*/
|
||||||
|
function addWatermark(container, watermarkTxt, explicitWidth = null, explicitHeight = null) {
|
||||||
|
if (!isNotEmpty(watermarkTxt)) return;
|
||||||
|
|
||||||
|
// 公共配置
|
||||||
|
const settings = {
|
||||||
|
start_x: 80,
|
||||||
|
start_y: 80,
|
||||||
|
x_space: 80,
|
||||||
|
y_space: 80,
|
||||||
|
color: 'black',
|
||||||
|
alpha: 0.2,
|
||||||
|
fontsize: '18px',
|
||||||
|
font: '微软雅黑',
|
||||||
|
width: 200,
|
||||||
|
height: 80,
|
||||||
|
angle: 30
|
||||||
|
};
|
||||||
|
|
||||||
|
// 确定实际使用的宽高
|
||||||
|
let pageWidth, pageHeight;
|
||||||
|
if (explicitWidth !== null && explicitHeight !== null) {
|
||||||
|
pageWidth = explicitWidth;
|
||||||
|
pageHeight = explicitHeight;
|
||||||
|
} else {
|
||||||
|
const rect = container.getBoundingClientRect();
|
||||||
|
pageWidth = rect.width;
|
||||||
|
pageHeight = rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
let maxX = pageWidth - settings.width;
|
||||||
|
let maxY = pageHeight - settings.height;
|
||||||
|
maxX = Math.max(maxX, 250);
|
||||||
|
maxY = Math.max(maxY, 250);
|
||||||
|
|
||||||
|
const fragment = document.createDocumentFragment();
|
||||||
|
for (let x = settings.start_x; x < maxX; x += settings.x_space) {
|
||||||
|
for (let y = settings.start_y; y < maxY; y += settings.y_space) {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.className = 'mask_div';
|
||||||
|
div.appendChild(document.createTextNode(watermarkTxt));
|
||||||
|
div.style.cssText = `
|
||||||
|
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=${settings.alpha * 100});
|
||||||
|
transform: rotate(-${settings.angle}deg);
|
||||||
|
visibility: visible;
|
||||||
|
position: absolute;
|
||||||
|
left: ${x}px;
|
||||||
|
top: ${y}px;
|
||||||
|
overflow: hidden;
|
||||||
|
z-index: 100;
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: ${settings.alpha};
|
||||||
|
font-size: ${settings.fontsize};
|
||||||
|
font-family: ${settings.font};
|
||||||
|
color: ${settings.color};
|
||||||
|
text-align: center;
|
||||||
|
width: ${settings.width}px;
|
||||||
|
height: ${settings.height}px;
|
||||||
|
display: block;
|
||||||
|
`;
|
||||||
|
fragment.appendChild(div);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
container.appendChild(fragment);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******/ var __webpack_modules__ = ({
|
/******/ var __webpack_modules__ = ({
|
||||||
|
|
||||||
/***/ 34:
|
/***/ 34:
|
||||||
@@ -13874,37 +13951,43 @@ class PDFPrintService {
|
|||||||
};
|
};
|
||||||
return new Promise(renderNextPage);
|
return new Promise(renderNextPage);
|
||||||
}
|
}
|
||||||
useRenderedPage() {
|
useRenderedPage() {
|
||||||
this.throwIfInactive();
|
this.throwIfInactive();
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
|
const wrapper = document.createElement("div");
|
||||||
|
wrapper.className = "printedPage";
|
||||||
|
wrapper.style.position = "relative";
|
||||||
|
|
||||||
|
// 获取当前页面的尺寸(单位:点,1pt=1/72英寸)
|
||||||
|
const pageSizePt = this.pagesOverview[0];
|
||||||
|
// 转换为 CSS 像素(1pt = 96/72 px)
|
||||||
|
const pageWidthPx = pageSizePt.width * 96 / 72;
|
||||||
|
const pageHeightPx = pageSizePt.height * 96 / 72;
|
||||||
|
|
||||||
|
// 设置 wrapper 尺寸(CSS 像素)
|
||||||
|
wrapper.style.width = `${pageWidthPx}px`;
|
||||||
|
wrapper.style.height = `${pageHeightPx}px`;
|
||||||
|
wrapper.style.backgroundColor = "white";
|
||||||
|
|
||||||
this.scratchCanvas.toBlob(blob => {
|
this.scratchCanvas.toBlob(blob => {
|
||||||
img.src = URL.createObjectURL(blob);
|
img.src = URL.createObjectURL(blob);
|
||||||
});
|
});
|
||||||
const wrapper = document.createElement("div");
|
|
||||||
wrapper.className = "printedPage";
|
|
||||||
wrapper.append(img);
|
wrapper.append(img);
|
||||||
var printWatermarkDiv = document.createElement('div');
|
|
||||||
// console.log(pageSize);
|
|
||||||
printWatermarkDiv.style.position = 'absolute';
|
|
||||||
printWatermarkDiv.style.left = '0px';
|
|
||||||
printWatermarkDiv.style.top = '0px';
|
|
||||||
printWatermarkDiv.style.width = '1024px';
|
|
||||||
printWatermarkDiv.style.height = pageSize.height*pageCount+ "px";
|
|
||||||
watermarkObj(printWatermarkDiv,watermarkTxt);
|
|
||||||
wrapper.appendChild(printWatermarkDiv);
|
|
||||||
this.printContainer.append(wrapper);
|
this.printContainer.append(wrapper);
|
||||||
const {
|
|
||||||
promise,
|
const { promise, resolve, reject } = Promise.withResolvers();
|
||||||
resolve,
|
img.onload = () => {
|
||||||
reject
|
// 使用专用函数生成水印,直接传入页面像素尺寸
|
||||||
} = Promise.withResolvers();
|
addWatermark(wrapper, watermarkTxt, pageWidthPx, pageHeightPx);
|
||||||
img.onload = resolve;
|
resolve();
|
||||||
|
};
|
||||||
img.onerror = reject;
|
img.onerror = reject;
|
||||||
promise.catch(() => {}).then(() => {
|
promise.catch(() => {}).then(() => {
|
||||||
URL.revokeObjectURL(img.src);
|
URL.revokeObjectURL(img.src);
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
performPrint() {
|
performPrint() {
|
||||||
this.throwIfInactive();
|
this.throwIfInactive();
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
@@ -17612,7 +17695,7 @@ class PDFPageView extends BasePDFPageView {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
watermarkObj(div,watermarkTxt);
|
addWatermark(div,watermarkTxt);
|
||||||
if (!this.annotationLayer && this.#annotationMode !== AnnotationMode.DISABLE) {
|
if (!this.annotationLayer && this.#annotationMode !== AnnotationMode.DISABLE) {
|
||||||
const {
|
const {
|
||||||
annotationStorage,
|
annotationStorage,
|
||||||
@@ -23083,7 +23166,7 @@ initCom(PDFViewerApplication);
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
const HOSTED_VIEWER_ORIGINS = new Set(["null", "http://mozilla.github.io", "https://mozilla.github.io"]);
|
const HOSTED_VIEWER_ORIGINS = new Set(["null", "http://mozilla.github.io", "https://mozilla.github.io"]);
|
||||||
var validateFileURL = function (file) {
|
var validateFileURL = function (file) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -23091,6 +23174,7 @@ initCom(PDFViewerApplication);
|
|||||||
if (HOSTED_VIEWER_ORIGINS.has(viewerOrigin)) {
|
if (HOSTED_VIEWER_ORIGINS.has(viewerOrigin)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
/* 注释掉跨域检查
|
||||||
const fileOrigin = URL.parse(file, window.location)?.origin;
|
const fileOrigin = URL.parse(file, window.location)?.origin;
|
||||||
if (fileOrigin === viewerOrigin) {
|
if (fileOrigin === viewerOrigin) {
|
||||||
return;
|
return;
|
||||||
@@ -23100,7 +23184,8 @@ initCom(PDFViewerApplication);
|
|||||||
message: ex.message
|
message: ex.message
|
||||||
});
|
});
|
||||||
throw ex;
|
throw ex;
|
||||||
};
|
*/
|
||||||
|
};
|
||||||
var onFileInputChange = function (evt) {
|
var onFileInputChange = function (evt) {
|
||||||
if (this.pdfViewer?.isInPresentationMode) {
|
if (this.pdfViewer?.isInPresentationMode) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,55 +1,83 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0">
|
||||||
<title>PDF预览</title>
|
<title>PDF预览</title>
|
||||||
<#include "*/commonHeader.ftl">
|
<#include "*/commonHeader.ftl">
|
||||||
<script src="js/base64.min.js" type="text/javascript"></script>
|
<script src="js/base64.min.js" type="text/javascript"></script>
|
||||||
|
<style>
|
||||||
|
/* 简单全屏布局,无滚动条 */
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
iframe {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: none;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.img-preview {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 20px;
|
||||||
|
right: 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
z-index: 999;
|
||||||
|
width: 48px;
|
||||||
|
height: 48px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<#if pdfUrl?contains("http://") || pdfUrl?contains("https://")>
|
<#if pdfUrl?contains("http://") || pdfUrl?contains("https://")>
|
||||||
<#assign finalUrl="${pdfUrl}">
|
<#assign finalUrl="${pdfUrl}">
|
||||||
<#else>
|
<#else>
|
||||||
<#assign finalUrl="${baseUrl}${pdfUrl}">
|
<#assign finalUrl="${baseUrl}${pdfUrl}">
|
||||||
</#if>
|
</#if>
|
||||||
<iframe src="" width="100%" frameborder="0"></iframe>
|
|
||||||
|
<iframe id="pdfFrame" src="about:blank"></iframe>
|
||||||
|
|
||||||
<#if "false" == switchDisabled>
|
<#if "false" == switchDisabled>
|
||||||
<img src="images/jpg.svg" width="48" height="48" style="position: fixed; cursor: pointer; top: 40%; right: 48px; z-index: 999;" alt="使用图片预览" title="使用图片预览" onclick="goForImage()"/>
|
<img class="img-preview" src="images/jpg.svg" alt="使用图片预览" title="使用图片预览" onclick="goForImage()"/>
|
||||||
</#if>
|
</#if>
|
||||||
</body>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var url = '${finalUrl}';
|
var url = '${finalUrl}';
|
||||||
var kkagent = '${kkagent}';
|
var kkagent = '${kkagent}';
|
||||||
var baseUrl = '${baseUrl}'.endsWith('/') ? '${baseUrl}' : '${baseUrl}' + '/';
|
var baseUrl = '${baseUrl}'.endsWith('/') ? '${baseUrl}' : '${baseUrl}' + '/';
|
||||||
if (kkagent === 'true' || !url.startsWith(baseUrl)) {
|
if (kkagent === 'true' || !url.startsWith(baseUrl)) {
|
||||||
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(Base64.encode(url))+ "&key=${kkkey}";
|
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(Base64.encode(url)) + "&key=${kkkey}";
|
||||||
}
|
|
||||||
document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?file=" + encodeURIComponent(url) + "&disablepresentationmode=${pdfPresentationModeDisable}&disableopenfile=${pdfOpenFileDisable}&disableprint=${pdfPrintDisable}&disabledownload=${pdfDownloadDisable}&disablebookmark=${pdfBookmarkDisable}&disableediting=${pdfDisableEditing}#page=1&pagemode=thumbs";
|
|
||||||
document.getElementsByTagName('iframe')[0].height = document.documentElement.clientHeight - 10;
|
|
||||||
/**
|
|
||||||
* 页面变化调整高度
|
|
||||||
*/
|
|
||||||
window.onresize = function () {
|
|
||||||
var fm = document.getElementsByTagName("iframe")[0];
|
|
||||||
fm.height = window.document.documentElement.clientHeight - 10;
|
|
||||||
}
|
}
|
||||||
|
var viewerUrl = baseUrl + "pdfjs/web/viewer.html?file=" + encodeURIComponent(url);
|
||||||
|
var watermarkEncoded = encodeURIComponent('${watermarkTxt?js_string}');
|
||||||
|
var highlightEncoded = encodeURIComponent('${highlightall?js_string}');
|
||||||
|
viewerUrl += "&disablepresentationmode=${pdfPresentationModeDisable}";
|
||||||
|
viewerUrl += "&disableopenfile=${pdfOpenFileDisable}";
|
||||||
|
viewerUrl += "&disableprint=${pdfPrintDisable}";
|
||||||
|
viewerUrl += "&disabledownload=${pdfDownloadDisable}";
|
||||||
|
viewerUrl += "&disablebookmark=${pdfBookmarkDisable}";
|
||||||
|
viewerUrl += "&disableediting=${pdfDisableEditing}";
|
||||||
|
viewerUrl += "&watermarktxt=" + watermarkEncoded;
|
||||||
|
viewerUrl += "&pdfhighlightall=" + highlightEncoded;
|
||||||
|
viewerUrl += "#page=${page}"; // ?c 确保数字不包含千位分隔符
|
||||||
|
viewerUrl += "&pagemode=thumbs";
|
||||||
|
var iframe = document.getElementById('pdfFrame');
|
||||||
|
iframe.src = viewerUrl;
|
||||||
|
|
||||||
|
// 图片预览切换
|
||||||
function goForImage() {
|
function goForImage() {
|
||||||
var url = window.location.href
|
var href = window.location.href;
|
||||||
if (url.indexOf("officePreviewType=pdf") != -1) {
|
if (href.indexOf("officePreviewType=pdf") !== -1) {
|
||||||
url = url.replace("officePreviewType=pdf", "officePreviewType=image");
|
href = href.replace("officePreviewType=pdf", "officePreviewType=image");
|
||||||
} else {
|
} else {
|
||||||
url = url + "&officePreviewType=image";
|
href += (href.indexOf('?') === -1 ? '?' : '&') + "officePreviewType=image";
|
||||||
}
|
}
|
||||||
window.location.href = url;
|
window.location.href = href;
|
||||||
}
|
|
||||||
|
|
||||||
/*初始化水印*/
|
|
||||||
window.onload = function () {
|
|
||||||
initWaterMark();
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user