feat: 添加eslint和prettier配置文件

master
luoer 2023-09-11 11:44:38 +08:00
parent 47fc92ebc7
commit 22b57e9fa7
21 changed files with 47 additions and 423 deletions

1
.eslintrc.json Normal file
View File

@ -0,0 +1 @@
{}

5
.prettierrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"tabWidth": 2,
"printWidth": 120,
"bracketSpacing": true
}

View File

@ -17,17 +17,14 @@
## 快速开始
1. 确保本地安装有如下软件,推荐最新版本。
1. 确保本地安装有如下软件,推荐最新版本。备注Pnpm 在 NodeJS v16+ 版本可通过 corepack enable 命令开启,低版本请通过 npm install pnpm 命令安装。
```bash
# 官网https://git-scm.com/
git
# 官网https://nodejs.org/en
node
# 备注在NodeJS v16+版本可通过 corepack enable 命令开启,低版本请通过 npm install pnpm 命令安装
pnpm
node + pnpm
```
2. 拉取模板

View File

@ -1,11 +1,11 @@
{
"hash": "3930064b",
"browserHash": "71254bdf",
"hash": "f14be980",
"browserHash": "16a0d7a2",
"optimized": {
"vue": {
"src": "../../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js",
"src": "../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js",
"fileHash": "9e6f557b",
"fileHash": "e275f4f9",
"needsInterop": false
}
},

View File

@ -1,4 +1,4 @@
// ../../../node_modules/.pnpm/@vue+shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.js
// node_modules/.pnpm/@vue+shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.js
function makeMap(str, expectsLowerCase) {
const map2 = /* @__PURE__ */ Object.create(null);
const list = str.split(",");
@ -256,7 +256,7 @@ var replacer = (_key, val) => {
return val;
};
// ../../../node_modules/.pnpm/@vue+reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
// node_modules/.pnpm/@vue+reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
function warn(msg, ...args) {
console.warn(`[Vue warn] ${msg}`, ...args);
}
@ -1410,7 +1410,7 @@ function computed(getterOrOptions, debugOptions, isSSR = false) {
}
var tick = Promise.resolve();
// ../../../node_modules/.pnpm/@vue+runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js
// node_modules/.pnpm/@vue+runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js
var stack = [];
function pushWarningContext(vnode) {
stack.push(vnode);
@ -9125,7 +9125,7 @@ var ssrUtils = _ssrUtils;
var resolveFilter = null;
var compatUtils = null;
// ../../../node_modules/.pnpm/@vue+runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js
// node_modules/.pnpm/@vue+runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js
var svgNS = "http://www.w3.org/2000/svg";
var doc = typeof document !== "undefined" ? document : null;
var templateContainer = doc && doc.createElement("template");
@ -9488,7 +9488,7 @@ var defineSSRCustomElement = (options) => {
};
var BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {
};
var VueElement = class extends BaseClass {
var VueElement = class _VueElement extends BaseClass {
constructor(_def, _props = {}, hydrate2) {
super();
this._def = _def;
@ -9659,7 +9659,7 @@ var VueElement = class extends BaseClass {
};
let parent = this;
while (parent = parent && (parent.parentNode || parent.host)) {
if (parent instanceof VueElement) {
if (parent instanceof _VueElement) {
instance.parent = parent._instance;
instance.provides = parent._instance.provides;
break;
@ -10619,7 +10619,7 @@ var initDirectivesForSSR = () => {
}
};
// ../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js
// node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js
function initDev() {
{
initCustomFormatter();

File diff suppressed because one or more lines are too long

View File

@ -6,14 +6,14 @@ import { defineConfig } from "vitepress";
*/
export default defineConfig({
lang: "zh-CN",
title: "绝弹博客",
title: "AppnifyVUE",
description: "一位前端开发者的博客",
/**
*
* @see https://vitepress.dev/reference/default-theme-config
*/
themeConfig: {
logo: "/juetan.jpg",
logo: "/favicon.ico",
search: {
provider: "local",
options: {
@ -43,29 +43,16 @@ export default defineConfig({
link: "/",
},
{
text: "前端开发",
link: "/front-end/",
text: "项目概览",
link: "/overview/",
},
{
text: "后端开发",
items: [
{
text: "测试1",
link: "/test1",
text: "开发文档",
link: '/dev'
},
{
text: "测试2",
link: "/test2",
},
],
},
{
text: '日常记录',
link: '/'
},
{
text: "开发工具",
link: "/dev-tools",
text: '关于',
link: '/about'
},
],
sidebar: {

View File

@ -94,158 +94,3 @@
--vp-custom-block-tip-text: var(--vp-c-brand-lightest);
--vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
}
/**
* Component: Algolia
* -------------------------------------------------------------------------- */
.DocSearch {
--docsearch-primary-color: var(--vp-c-brand) !important;
}
.Layout {
background-color: #f1f3f5;
}
#VPContent .VPDoc.has-aside .content-container {
max-width: initial;
margin: 0;
}
.VPNav {
border-bottom: 1px solid #f1f3f5;
background: #fff;
}
.curtain,
.aside-curtain {
display: none;
}
#VPContent .aside {
padding-left: 20px;
}
@media (min-width: 640px) {
.vp-doc div[class*="language-"] {
border-radius: 2px;
}
}
#VPSidebarNav {
margin-top: 20px;
background: #fff;
padding: 16px;
}
#VPSidebarNav .group {
padding-top: 0;
}
#app .VPSidebar {
width: calc((100% - (var(--vp-layout-max-width) - 64px)) / 2 + var(--vp-sidebar-width) - 20px);
padding-right: 24px;
}
#app .aside-container {
padding-top: calc(var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + var(--vp-doc-top-height, 0px) + 20px);
}
#app .aside {
max-width: 228px;
}
#app .pager-link {
border-radius: 4px;
}
#app .VPNavBarTitle.has-sidebar .title {
border-bottom-color: transparent;
}
#app .VPMenu {
border-radius: 2px;
}
/**
* Component: Home
* -------------------------------------------------------------------------- */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
.content img {
border: 1px solid #e1f1f1;
border-radius: 2px;
}
.item {
width: 100%;
overflow: hidden;
}
.link {
width: 100%;
}
.text {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
body {
font-size: 14px;
}
.VPSidebarItem {
/* padding: 0 8px; */
}
.items > .VPSidebarItem.level-1 {
margin-top: 4px;
padding: 0 8px;
}
.items > .VPSidebarItem.level-1.is-active {
background: hsl(204 100% 95% / 1);
/* padding: 0 8px; */
border-radius: 2px;
}
.vp-doc tr:nth-child(2n) {
background-color: transparent;
}
.vp-doc h2 {
margin: 32px 0 16px;
border-top: none;
padding-top: 0;
border-bottom: 1px solid var(--vp-c-divider);
padding-bottom: 8px;
letter-spacing: -0.02em;
line-height: 32px;
font-size: 24px;
font-weight: 600;
}
.vp-doc a {
display: none;
}
.VPNavBarTitle .title {
font-weight: 400;
}

View File

@ -1,85 +0,0 @@
# 日常开发中如何利用 EJS 模板引擎辅助生成代码?
在如今的前端开发中,[EJS](https://ejs.bootcss.com/) 已经是一个过时的开发方案,但其实在辅助开发方面还是用处的。话不多说,接下来以一个例子来感受下。
## 例子
在日常开发中,有时候会遇到后端有一些枚举字典的定义,前端也要进行相应的配置。例如在做权限功能时,后端给了我们下面的权限码数据:
```json
[
{
"id": 1,
"code": "access:readAbc",
"authName": "读取权限",
"level": 1
},
{
"id": 2,
"code": "access:writeAbc",
"authName": "写入权限"
}
]
```
我们需要把他做成枚举的形式, 也就是下面的形式:
```typescript
/**
* 权限码
*/
export const enum AuthEnum {
/**
* 读取权限
*/
ReadAbc = "access:readAbc",
/**
* 写入权限
*/
WriteAbc = "access:writeAbc",
}
```
那么如何从这项无聊的工作中解放出来呢,操作也比较简单。
1\. 首先打开一个能编译 EJS 的在线网站, 例如 [One Compiler](https://onecompiler.com/ejs)。
![One Compiler](./onecompiler-ejs.png)
2\. 根据目标数据结构整理下代码,点击`RUN`按钮即可。
```typescript
<%
let items = [
{
"id": 1,
"code": "access:readAbc",
"authName": "读取权限",
},
{
"id": 2,
"code": "access:writeAbc",
"authName": "写入权限",
},
]
items = items.map(item => {
let key = item.code.substring(7);
key = key.charAt(0).toUpperCase() + key.slice(1)
return { ...item, key }
})
-%>
/**
* 权限码
*/
export const enum DaEnum {
<% items.forEach((i, index) => { -%>
/**
* <%= i.authName %>
*/
<%= i.key %> = '<%= i.code %>',
<% }) -%>
}
```
## 结语
以上这是一个简单的例子但在命令行工具进行页面模板的生成方面可能用得比较多。另外EJS 的语法也不难,在一些重复性的代码生成方面还是不错的。

View File

@ -1 +0,0 @@
前端

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

View File

@ -1,112 +0,0 @@
# 从new xx()和new xx的区别中整理JS中操作符的优先级
## 问题
最近在工作中写日期格式化时,遇到一个问题,先来看下面的代码:
```typescript
// 写法一
new Date().toISOString
// 写法二
new Date.toISOString;
```
执行如下:
![](./new-()and-new.png)
猜测是优先级的问题然后在MDN找到了[答案](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Operator_precedence#%E6%B1%87%E6%80%BB%E8%A1%A8),它们确实是两个不同的优先级,如下图:
![](./js-diff-new()-and-new.png)
以上,方式一中的 `.` 优先级最高,但其左边需要先求值,因而先执行`new Date()`得到实例,再返回实例上的`toISOString`属性;而方式二中的 `. `优先级也是最高,但其左边不用求值,因而可以先执行`Date.toISOString`得到`toISOString`值(Date上不存在该属性因此该值为undefined),再尝试进行`new toISOString`操作时报错发生。
## 优先级
我印象中的运算符只有四十几个没想到在MDN里面找到的有六十几个。说实话上面的运算符以前真没注意过趁着空闲我决定将这些运算符整理下整理后总体分为下面的五大类
### 一级运算符
大部分是一元操作符。
| 运算符 | 类型 | 说明
| :--- | :--- | ---
| ( … ) | 分组 | 优先级最高的运算符
| … . … | 成员访问 | 静态访问
| [] | 需计算的成员访问 | 动态访问
| new xx() | new带参数列表 | 实例化
| () | 函数调用 | 函数调用
| ?. | 可选链Optional chaining | `a?.b`类似于`a === null \|\| a === void 0 ? void 0 : a.b;`
| new … | new无参数列表 | 实例化
| … ++ | 后置递增 | 先返回再+1例如 `let a = 1; const b = a++; // b: 1 a: 2`。比较常见的是在for循环中进行后置递增。
| … -- | 后置递减 | 同上
| ! … | 逻辑非 (!) |
| ~ … | 按位非 (~) |
| + … | 一元加法 (+) | 可用于把字符串转换为数值,例如`+'1'`将得到`1`。
| - … | 一元减法 (-) | 同上
| ++ … | 前置递增 | 与后置递增不同,先执行+1再返回
| -- … | 前置递减 | 同上
| typeof … | typeof | 返回值只有这几个string \| number \| boolean \| undefined \| null \| function \| object
| void … | void | 比较常见的是使用`void 0`代替undefined因为在以前undefined是可以作为变量名使用的。
| delete … | delete | 删除对象的属性
| await … | await | 等待某个promise执行成功
### 算符运算符
| 运算符 | 类型 | 说明
| :--- | :--- | ---
| … ** … | 幂 (**) |
| … * … | 乘法 (*) |
| … / … | 除法 (/) |
| … % … | 取余 (%) |
| … + … | 加法 (+) |
| … - … | 减法 (-) |
| … &lt;&lt; … | 按位左移 (&lt;&lt;) | 通常用于二进制数据的移位, 例如:`(4)<<1` `8``4``100`, `1000``8`
| … &gt;&gt; … | 按位右移 (&gt;&gt;) | 同上
| … &gt;&gt;&gt; … | 无符号右移 (&gt;&gt;&gt;) | 同上
| … &lt; … | 小于 (&lt;) | 对于数值,比较大小
| … &lt;= … | 小于等于 (&lt;=) |
| … &gt; … | 大于 (&gt;) |
| … &gt;= … | 大于等于 (&gt;=) |
### 比较运算符
| 运算符 | 类型 | 说明
| :--- | :--- | ---
| … in … | in | 判断某个属性是否存在于对象上,会顺着原型链进行查找,可以用`Object.prototype.hasOwnProperty.call(obj, 'xx')`进行检测自身的属性是否存在。
| … instanceof … | instanceof | 判断右边的对象,是否在左边对象的原型链上。
| … == … | 相等 (==) | 左右两边的值可能会先做隐式转换,再进行比较,例如: `'1' == 1 //true`
| … != … | 不相等 (!=) | 同上
| … === … | 一致/严格相等 (===) | 左右两边的值不做隐式转换,直接比较,例如:`'1' === 1 // false`
| … !== … | 不一致/严格不相等 (!==) | 同上
### 布尔运算符
| 运算符 | 类型 | 说明
| :--- | :--- | ---
| … &amp; … | 按位与 (&amp;) | 常用于对二进制数值进行操作
| … ^ … | 按位异或 (^) |
| … \| … | 按位或 (\|) |
| … &amp;&amp; … | 逻辑与 (&amp;&amp;) |
| … \|\| … | 逻辑或 (||) |
| … ?? … | 空值合并 (??) | 当左边的值不为undefined或null时返回左边否则返回右边 具体代码可能是这样的\n: `a !== null && a !== void 0 ? a : b;` |
### 赋值运算符
| 运算符 | 类型 | 说明
| :--- | :--- | ---
| … ? … : … | 条件(三元)运算符 | 可以在简单场景中代替if/else使用不过自从出了??运算符,这个运算符用的比较少
| … = … | 赋值 |
| … += … |
| … -= … |
| … **= … |
| … *= … |
| … /= … |
| … %= … |
| … &lt;&lt;= … |
| … &gt;&gt;= … |
| … &gt;&gt;&gt;= … |
| … &amp;= … |
| … ^= … |
| … |= … |
| … &amp;&amp;= … |
| … ||= … |
| … ??= … |
| … , … | 逗号 / 序列 | 优先级最低的运算符,由于其会返回最后一个值,在某些简短操作中也会用到,例如:`const map = items.reduce((m, i) => (m[i.id]=i,m), {})`
## 结语
优先级的重要性不言而喻,往后还是要多多温习。

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

View File

@ -3,15 +3,15 @@
layout: home
hero:
name: "绝弹博客"
name: "Appnify"
text: ""
tagline: 一位前端开发者的博客
tagline: 基于 vue3 + vite 的后台管理系统模板
actions:
- theme: brand
text: 首页
text: 概览
link: /markdown-examples
- theme: alt
text: 测试页面
text: 开发文档
link: /api-examples
image:
src: /assets/td.svg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -1,5 +1,5 @@
{
"name": "common",
"name": "starter-vue",
"private": true,
"version": "0.0.0",
"type": "module",
@ -9,14 +9,7 @@
"preview": "vite preview",
"new": "cd ./scripts/plop && plop",
"api": "tsx ./scripts/openapi/index.ts",
"release": "release-it --config ./scripts/release/index.cjs",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs"
},
"prettier": {
"tabWidth": 2,
"printWidth": 120
"release": "release-it --config ./scripts/release/index.cjs"
},
"devDependencies": {
"@arco-design/web-vue": "^2.44.4",

View File

@ -8,9 +8,9 @@ class Constant<T extends Item[]> {
constructor(public raw: T) {}
/**
*
*
* @param value
* @param key label
* @param key label
* @returns
*/
fmt<K extends T[number]["value"]>(value: K, key?: keyof T[number]) {
@ -27,23 +27,17 @@ class Constant<T extends Item[]> {
}
/**
*
* @param value
*
* @param value
* @returns
*/
get(value: any) {
return this.raw.find((item) => item.value === value);
}
/**
*
* @param items
* @returns
*/
static from<T extends Item[]>(items: T) {
return new Constant(items);
}
}
export { Constant };
const defineConstants = <T extends Item[]>(items: T) => {
return new Constant(items);
};
export { defineConstants };

View File

@ -1,4 +1,4 @@
import { Constant } from "@/utils";
import { defineConstants } from "./defineConstants";
/**
*
@ -21,7 +21,7 @@ enum Gender {
/**
*
*/
const GenderDict = Constant.from([
const Genders = defineConstants([
{
value: Gender.Man,
label: "男",
@ -39,5 +39,5 @@ const GenderDict = Constant.from([
},
]);
export { Gender, GenderDict };
export { Gender, Genders };

View File

@ -1 +1,2 @@
export * from "./gender";
export * from "./defineConstants";

View File

@ -1,3 +1,2 @@
export * from "./constant";
export * from "./delConfirm";