fix mine
This commit is contained in:
parent
17a02ea47e
commit
70e7a113e6
22 changed files with 967 additions and 285 deletions
|
@ -20,16 +20,20 @@ Page({
|
|||
*/
|
||||
onLoad: function (options) {
|
||||
// 准备初始数据
|
||||
const type = (options.type || 'totp').toLowerCase();
|
||||
const isHotp = type === 'hotp';
|
||||
|
||||
const initialData = {
|
||||
type: options.type || 'totp',
|
||||
type: type,
|
||||
formData: {
|
||||
issuer: '',
|
||||
remark: '',
|
||||
account: '',
|
||||
secret: '',
|
||||
algo: 'SHA1',
|
||||
algorithm: 'SHA1',
|
||||
digits: '6',
|
||||
period: '30',
|
||||
counter: '0'
|
||||
// 只有HOTP类型才设置counter初始值
|
||||
...(isHotp ? { counter: '0' } : {})
|
||||
},
|
||||
pageReady: true // 直接设置为ready状态
|
||||
};
|
||||
|
@ -41,15 +45,19 @@ Page({
|
|||
const parsedToken = parseURL(scanData);
|
||||
|
||||
if (parsedToken) {
|
||||
initialData.type = parsedToken.type;
|
||||
const type = (parsedToken.type || 'totp').toLowerCase();
|
||||
const isHotp = type === 'hotp';
|
||||
|
||||
initialData.type = type;
|
||||
initialData.formData = {
|
||||
issuer: parsedToken.issuer || '',
|
||||
remark: parsedToken.remark || '',
|
||||
account: parsedToken.account || '',
|
||||
secret: parsedToken.secret || '',
|
||||
algo: parsedToken.algo || 'SHA1',
|
||||
algorithm: parsedToken.algorithm || 'SHA1',
|
||||
digits: parsedToken.digits || '6',
|
||||
period: parsedToken.period || '30',
|
||||
counter: parsedToken.counter || '0'
|
||||
// 只有HOTP类型才设置counter
|
||||
...(isHotp ? { counter: parsedToken.counter || '0' } : {})
|
||||
};
|
||||
|
||||
// 立即显示成功提示
|
||||
|
@ -91,8 +99,8 @@ Page({
|
|||
if (!values.issuer || !values.issuer.trim()) {
|
||||
throw new Error('请输入服务名称');
|
||||
}
|
||||
if (!values.remark || !values.remark.trim()) {
|
||||
throw new Error('请输入账号备注');
|
||||
if (!values.account || !values.account.trim()) {
|
||||
throw new Error('请输入账户名称');
|
||||
}
|
||||
if (!values.secret || !values.secret.trim()) {
|
||||
throw new Error('请输入密钥');
|
||||
|
@ -100,16 +108,16 @@ Page({
|
|||
|
||||
// 格式化数据
|
||||
const tokenData = {
|
||||
type: values.type,
|
||||
type: this.data.type,
|
||||
issuer: values.issuer.trim(),
|
||||
remark: values.remark.trim(),
|
||||
account: values.account.trim(),
|
||||
secret: values.secret.trim().toUpperCase(),
|
||||
algo: values.algo,
|
||||
algorithm: values.algorithm,
|
||||
digits: parseInt(values.digits, 10)
|
||||
};
|
||||
|
||||
// 类型特定字段
|
||||
if (values.type === 'totp') {
|
||||
if (this.data.type === 'totp') {
|
||||
const period = parseInt(values.period, 10);
|
||||
if (isNaN(period) || period < 15 || period > 300) {
|
||||
throw new Error('更新周期必须在15-300秒之间');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue