-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
186 lines (168 loc) · 8.35 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MobaXterm Keygen</title>
<script src="./js/vue.min-2.6.12.js"></script>
<script src="./js/FileSaver.js"></script>
<script src="./js/jszip.js"></script>
<link href="./css/pure-min.css" rel="stylesheet" />
<link href="./css/style.css" rel="stylesheet" />
</head>
<body>
<div class="box-main">
<div id="app">
<div class="content">
<div class="pure-form pure-form-aligned auto-center">
<fieldset>
<legend>
<h1 class="text-center">MobaXterm Keygen</h1>
</legend>
<div class="pure-g">
<div class="pure-control-group pure-u-1">
<label for="licenseType">版 本:</label>
<select name="licenseType" id="licenseType" v-model="licenseType">
<!-- <option value="">请选择</option> -->
<option v-for="(val, key) in LICENSE_TYPES" :value="val">{{key}}</option>
</select>
</div>
<div class="pure-control-group pure-u-1">
<label for="userName">用户名:</label>
<my-input :idattr="'userName'" :validation="'^[a-zA-Z]+$'" :valueattr="userName"
:validationtips="'只能使用字母'" :placeholderattr="'示例 defaultUser'"
@set-data="setUserName">
</my-input>
</div>
<div class="pure-control-group pure-u-1">
<label for="versionName">版本号:</label>
<my-input :idattr="'versionName'" :validation="'^[1-9][0-9]*\\.?\\d{0,1}$'"
:validationtips="'小数且小数点后只能有1位'" :valueattr="versionName"
:placeholderattr="'示例 21.0'" @set-data="setVersionName"></my-input>
</div>
<div class="pure-control-group pure-u-1">
<label for="userNum">用户数:</label>
<my-input :idattr="'userNum'" :validation="'^[1-9]+\\d*$'" :valueattr="userNum"
:placeholderattr="'示例 1'" :validationtips="'数字且最小值为1'" @set-data="setUserNum">
</my-input>
</div>
<div class="pure-controls pure-u-1">
<button type="submit" class="pure-button pure-button-primary"
@click.stop="generate">生成</button>
</div>
</div>
</fieldset>
</div>
</div>
</div>
</div>
<script type="module">
import { LicenseType, generateLicense } from './js/mobaXtermGenerater.js'
var app = new Vue({
el: '#app',
data() {
return {
LICENSE_TYPES: LicenseType,
licenseType: 1,
userName: 'defaultUser',
versionName: '21.5',
userNum: 1,
}
},
methods: {
setUserName(newVal) {
this.userName = newVal;
},
setVersionName(newVal) {
this.versionName = newVal;
},
setUserNum(newVal) {
this.userNum = newVal;
},
generate() {
if (!this.userName) {
alert('请填写用户名');
return;
}
if (!this.versionName) {
alert('请填写版本号');
return;
}
if (!this.userNum) this.userNum = 1;
// 版本号拆分
let versionNameArr = this.versionName.split('.');
const majorVersion = parseInt(versionNameArr[0]);
const minorVersion = versionNameArr.length === 2 ? (parseInt(versionNameArr[1]) || 0) : 0;
// 生成license字符串
let licenseStr = generateLicense(this.licenseType, this.userName, this.userNum, majorVersion, minorVersion);
this.generateLicenseFile(licenseStr);
},
generateLicenseFile(licenseStr) {
let zip = new JSZip();
zip.file("Pro.key", licenseStr);
//var img = zip.folder("images");
//img.file("smile.gif", imgData, { base64: true });
zip.generateAsync({ type: "blob" })
.then(function (content) {
// see FileSaver.js
saveAs(content, "Custom.mxtpro");
});
}
},
components: {
'my-input': {
template: `<div class="my-input">
<input :id="idattr" :placeholder="placeholderattr" v-model="value" required/>
<div :class="validationTipsDiplay" class="my-input-tips-wrap">
<span class="my-input-tips">{{validationtips}}</span>
<div class="my-input-arrow"></div>
</div>
</div>`,
data() {
// 将组件外传入的 props 的 valueattr 赋值到当前的 data.value 值
// 同时本组件的 value 值是和当前变量双向绑定的
return {
value: this.valueattr,
validationTipsDiplay: 'hide',
tipsDisplayTimeout: undefined
}
},
props: {
// 接收父组件使用本组件时绑定的 idattr 属性值绑定到当前值
idattr: { type: String, default: '' },
placeholderattr: { type: String, default: '' },
valueattr: '',
validation: { type: String, default: '' }, // 校验正则
validationtips: ''
},
watch: {
valueattr(newVal, oldVal) {
// 监视 父组件传入的 valueattr 值的变化绑定到当前组件的 data.value 值
this.value = newVal
},
value(newVal, oldVal) {
if (newVal && this.validation) {
let reg = new RegExp(this.validation);
if (!reg.test(newVal)) {
this.validationTipsDiplay = '';
this.value = oldVal;
if (this.tipsDisplayTimeout) clearTimeout(this.tipsDisplayTimeout);
var _this = this;
this.tipsDisplayTimeout = setTimeout(function () {
_this.tipsDisplayTimeout = undefined;
_this.validationTipsDiplay = 'hide';
}, 1000);
return;
}
}
// 监视当前组件的 data.value 值触发父组件绑定的 set-data 事件改变父组件的值
this.$emit('set-data', newVal);
}
}
}
}
});
</script>
</body>
</html>