Skip to content

Commit d0bc1cd

Browse files
author
sky.sun
committed
doc
1 parent 3418e94 commit d0bc1cd

File tree

11 files changed

+2032
-154
lines changed

11 files changed

+2032
-154
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# LearnPython4Fe
2-
给前端开发者的Python入门教程
1+
# 给前端开发者的 Python 教程
2+
3+
状态:进行中

docs/.vitepress/components/PlaygroundEditor.vue

Lines changed: 101 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<div class="border-b border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800">
55
<div class="px-4 py-3 flex justify-between items-center">
66
<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">
89
<select v-model="selectedLang"
910
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">
1011
<option value="py">Python</option>
@@ -14,7 +15,6 @@
1415
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
1516
</svg>
1617
</div>
17-
<div class="text-xl text-gray-900 dark:text-gray-100">Playground</div>
1818
</div>
1919
<div class="flex items-center gap-2">
2020
<button @click="copyCode"
@@ -24,7 +24,7 @@
2424
<CheckIcon v-else :size="16" />
2525
<span>{{ copySuccess ? '已复制' : '复制' }}</span>
2626
</button>
27-
<button @click="() => runCode(selectedLang)"
27+
<button @click="() => runCode(selectedLang)"
2828
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"
2929
:disabled="isRunning || (selectedLang === 'py' && !pyodideReady)"
3030
:title="getButtonText(selectedLang)">
@@ -116,37 +116,109 @@ const {
116116
// 默认代码模板
117117
const defaultCode = computed(() => {
118118
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}")
133168
`
134169
} 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+
}
137190
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+
}
139208
140-
// 试试一些基本操作
141-
const name = "JavaScript"
142-
const year = 2024
143-
console.log(\`我正在学习 \${name} - \${year}\`)
209+
// 生成几个不同的密码选项
210+
console.log("推荐几个安全密码:\\n");
144211
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+
});
150222
`
151223
}
152224
})

0 commit comments

Comments
 (0)