|
4 | 4 | <div class="border-b border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800"> |
5 | 5 | <div class="px-4 py-3 flex justify-between items-center"> |
6 | 6 | <div class="flex items-center gap-3"> |
7 | | - <div class="lang-selector-container text-xl"> |
| 7 | + <div class="text-xl text-gray-900 dark:text-gray-100">代码实验室</div> |
| 8 | + <div class="lang-selector-container"> |
8 | 9 | <select v-model="selectedLang" |
9 | 10 | class="language-selector text-lg font-semibold bg-transparent border-none outline-none cursor-pointer text-gray-900 dark:text-gray-100 hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200"> |
10 | 11 | <option value="py">Python</option> |
|
14 | 15 | <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path> |
15 | 16 | </svg> |
16 | 17 | </div> |
17 | | - <div class="text-xl text-gray-900 dark:text-gray-100">Playground</div> |
18 | 18 | </div> |
19 | 19 | <div class="flex items-center gap-2"> |
20 | 20 | <button @click="copyCode" |
|
24 | 24 | <CheckIcon v-else :size="16" /> |
25 | 25 | <span>{{ copySuccess ? '已复制' : '复制' }}</span> |
26 | 26 | </button> |
27 | | - <button @click="() => runCode(selectedLang)" |
| 27 | + <button @click="() => runCode(selectedLang)" |
28 | 28 | class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-1.5 rounded-md text-sm cursor-pointer transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2" |
29 | 29 | :disabled="isRunning || (selectedLang === 'py' && !pyodideReady)" |
30 | 30 | :title="getButtonText(selectedLang)"> |
@@ -116,37 +116,109 @@ const { |
116 | 116 | // 默认代码模板 |
117 | 117 | const defaultCode = computed(() => { |
118 | 118 | if (selectedLang.value === 'py') { |
119 | | - return `# 欢迎使用 Python Playground |
120 | | -# 你可以在这里编写和运行 Python 代码 |
121 | | -
|
122 | | -print("Hello, Python!") |
123 | | -
|
124 | | -# 试试一些基本操作 |
125 | | -name = "Python" |
126 | | -version = 3.12 |
127 | | -print(f"我正在学习 {name} {version}") |
128 | | -
|
129 | | -# 创建一个简单的列表 |
130 | | -fruits = ["苹果", "香蕉", "橘子"] |
131 | | -for fruit in fruits: |
132 | | - print(f"我喜欢 {fruit}") |
| 119 | + return `# 密码生成器 |
| 120 | +
|
| 121 | +import random |
| 122 | +
|
| 123 | +def generate_password(length=12): |
| 124 | + """生成安全密码""" |
| 125 | + # 定义字符集 |
| 126 | + letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 127 | + numbers = "0123456789" |
| 128 | + symbols = "!@#$%^&*" |
| 129 | + |
| 130 | + # 组合所有字符 |
| 131 | + all_chars = letters + numbers + symbols |
| 132 | + |
| 133 | + # 生成密码 |
| 134 | + password = "" |
| 135 | + for i in range(length): |
| 136 | + password += random.choice(all_chars) |
| 137 | + |
| 138 | + return password |
| 139 | +
|
| 140 | +def get_strength_emoji(password): |
| 141 | + """根据密码特征返回强度表情""" |
| 142 | + has_upper = any(c.isupper() for c in password) |
| 143 | + has_lower = any(c.islower() for c in password) |
| 144 | + has_digit = any(c.isdigit() for c in password) |
| 145 | + has_symbol = any(c in "!@#$%^&*" for c in password) |
| 146 | + |
| 147 | + char_types = sum([has_upper, has_lower, has_digit, has_symbol]) |
| 148 | + |
| 149 | + if char_types == 4: |
| 150 | + return "🟢 强" |
| 151 | + elif char_types == 3: |
| 152 | + return "🟡 中等" |
| 153 | + else: |
| 154 | + return "🔴 弱" |
| 155 | +
|
| 156 | +# 生成几个不同的密码选项 |
| 157 | +print("推荐几个安全密码:\\n") |
| 158 | +
|
| 159 | +passwords = [ |
| 160 | + generate_password(12), |
| 161 | + generate_password(14), |
| 162 | + generate_password(16) |
| 163 | +] |
| 164 | +
|
| 165 | +for i, pwd in enumerate(passwords, 1): |
| 166 | + strength = get_strength_emoji(pwd) |
| 167 | + print(f"{i}. {pwd} {strength}") |
133 | 168 | ` |
134 | 169 | } else { |
135 | | - return `// 欢迎使用 JavaScript Playground |
136 | | -// 你可以在这里编写和运行 JavaScript 代码 |
| 170 | + return `// 密码生成器 |
| 171 | +
|
| 172 | +function generatePassword(length = 12) { |
| 173 | + // 生成安全密码 |
| 174 | + const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
| 175 | + const numbers = "0123456789"; |
| 176 | + const symbols = "!@#$%^&*"; |
| 177 | + |
| 178 | + // 组合所有字符 |
| 179 | + const allChars = letters + numbers + symbols; |
| 180 | + |
| 181 | + // 生成密码 |
| 182 | + let password = ""; |
| 183 | + for (let i = 0; i < length; i++) { |
| 184 | + const randomIndex = Math.floor(Math.random() * allChars.length); |
| 185 | + password += allChars[randomIndex]; |
| 186 | + } |
| 187 | + |
| 188 | + return password; |
| 189 | +} |
137 | 190 |
|
138 | | -console.log("Hello, JavaScript!") |
| 191 | +function getStrengthEmoji(password) { |
| 192 | + // 根据密码特征返回强度表情 |
| 193 | + const hasUpper = /[A-Z]/.test(password); |
| 194 | + const hasLower = /[a-z]/.test(password); |
| 195 | + const hasDigit = /[0-9]/.test(password); |
| 196 | + const hasSymbol = /[!@#$%^&*]/.test(password); |
| 197 | + |
| 198 | + const charTypes = [hasUpper, hasLower, hasDigit, hasSymbol].filter(Boolean).length; |
| 199 | + |
| 200 | + if (charTypes === 4) { |
| 201 | + return "🟢 强"; |
| 202 | + } else if (charTypes === 3) { |
| 203 | + return "🟡 中等"; |
| 204 | + } else { |
| 205 | + return "🔴 弱"; |
| 206 | + } |
| 207 | +} |
139 | 208 |
|
140 | | -// 试试一些基本操作 |
141 | | -const name = "JavaScript" |
142 | | -const year = 2024 |
143 | | -console.log(\`我正在学习 \${name} - \${year}\`) |
| 209 | +// 生成几个不同的密码选项 |
| 210 | +console.log("推荐几个安全密码:\\n"); |
144 | 211 |
|
145 | | -// 创建一个简单的数组 |
146 | | -const fruits = ["苹果", "香蕉", "橘子"] |
147 | | -fruits.forEach(fruit => { |
148 | | - console.log(\`我喜欢 \${fruit}\`) |
149 | | -}) |
| 212 | +const passwords = [ |
| 213 | + generatePassword(12), |
| 214 | + generatePassword(14), |
| 215 | + generatePassword(16) |
| 216 | +]; |
| 217 | +
|
| 218 | +passwords.forEach((pwd, index) => { |
| 219 | + const strength = getStrengthEmoji(pwd); |
| 220 | + console.log(\`\${index + 1}. \${pwd} \${strength}\`); |
| 221 | +}); |
150 | 222 | ` |
151 | 223 | } |
152 | 224 | }) |
|
0 commit comments