Skip to content

Commit

Permalink
feat: add permission
Browse files Browse the repository at this point in the history
  • Loading branch information
fewbadboy committed Sep 4, 2024
1 parent b136282 commit cc744a7
Show file tree
Hide file tree
Showing 40 changed files with 919 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# .lintstagedrc
{
'*.{js, jsx, ts, tsx}': [
'*.{js, jsx, ts, tsx, !src/utils/*.js}': [
'eslint --fix'
],
'*.vue': [
Expand Down
69 changes: 69 additions & 0 deletions doc/file stream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# File Stream

## Blob

```js
// type MIME Type https://www.iana.org/assignments/media-types/media-types.xhtml
new Blob(array, { type: '', endings })
URL.createObjectURL(File/Blob/MediaSource)
```

- arrayBuffer()
- slice()
- stream()
- text()

## File

```js
document.querySelector("input[type=file]").files[0]
```

`<input>` 元素选择文件后返回的 FileList 对象,或者拖拽生成的 DataTransfer 对象

## FileList

`<input>` 元素选择文件后返回的 FileList 对象,或者拖拽生成的 DataTransfer 对象

- item()

## FileReader

```js
document.querySelector("input[type=file]").files[0]
```

- readAsArrayBuffer(blob)
- readAsDataURL(blob)
- readAsText(blob[, encoding])

```js
async function test(file) {
const preview = document.querySelector("img")
return await new Promise((resolve, reject) => {
const reader = Object.assign(new FileReader(), {
onload: () => {
preview.src = reader.result
resolve()
},
onerror: () => reject(reader.error)
})
reader.readAsDataURL(file)
})
}

export async function loadImage(image) {
return new Promise((resolve, reject) => {
const img = new Image()
img.src = image
Object.assign(img, {
onload: () => {
resolve(img)
},
onerror: (error) => {
reject(error)
}
})
})
}
```
155 changes: 155 additions & 0 deletions doc/note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Note

## Custom Icon

### Icon Font

```vue
<script setup>
import iconFont from "./iconfont?url";
const IconFont = createFromIconfontCN({
/**
* 资源管理 - 我的项目
* 修改名称
* symbol 下查看新名称
* 1. 离线 - 下载本地 - 引入 iconfont.js 文件
* 2. 使用在线链接
*/
scriptUrl: iconFont,
});
</script>
<template>
<MyIcon type="icon-phone-signal-full" class="red" />
</template>
<style scoped lang="scss">
:deep(.red) {
color: red;
}
</style>
```

### SVG

```vue
<script setup>
import Icon from '@ant-design/icons-vue';
import MessageSvg from 'path/to/message.svg';
</script>
<template>
<Icon type={MessageSvg} />
</template>
```

## axios

### application/x-www-form-urlencoded

```js
// URLSearchParams is not supported by all browsers
const params = new URLSearchParams();
params.append('param1', 'value1');
params.append('param2', 'value2');
```

### multipart/form-data

```js
// new FormData(domRef.value)
const form = new FormData();
form.append('my_field', 'my value');
form.append('my_buffer', new Blob([1,2,3]));
form.append('my_file', fileInput.files[0]);

axios.post('https://example.com', form);
```

### Cancelling requests

```js
const controller = new AbortController();

axios.get('/foo/bar', {
// AbortSignal.timeout(5000)
signal: controller.signal
}).then(function(response) {
//...
});
// cancel the request
controller.abort()
```

## issues

`.css (Unknown at rule @tailwindcss(unknownAtRules)`

[RECOMMENDED FIX](https://github.com/tailwindlabs/tailwindcss/discussions/5258)

## 捕获 promise 失败的异常

```js
try {
const { data } = await new Promise((resolve, reject) => {
setTimeout(() => {
reject('custom error')
}, 2000)
}).catch((error) => {
console.log('inner', error)
})
console.log('data', error)
} catch(error) {
console.log('获取菜单失败',error)
}
// inner custom error
// 获取菜单失败 TypeError: Cannot destructure property 'data' of '(intermediate value)' as it is undefined.
```

## 自定义文件上传

```js
/**
* and design vue 上传组件,change 事件参数 file, fileList
* file 内部封装了 原生的 originFileObj 为 File 类型
*
* 原生的file 类型输入框,fileInput.files[0]
* */

const formData = new FormData()
// 可以给同一个值添加多个值完成多文件传输
formData.append('files', file.originFileObj)

postResult(formData).then(({ data }) => {
console.log(data)
})
```

## UTF-8 流解析

```js
// 默认使用 UTF-8 编码将码位流转换成字节流
const encoder = new TextEncoder('utf-8');
const array = encoder.encode("你好");

const utf8decoder = new TextDecoder('utf-8');
const u8arr = new Uint8Array([228, 189, 160, 229, 165, 189]);
utf8decoder.decode(u8arr);
```

## 加密

```js
// crypto-js
import CryptoJS from "crypto-js";

// Encrypt
var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123').toString();

// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
var originalText = bytes.toString(CryptoJS.enc.Utf8);

console.log(originalText);
```
55 changes: 55 additions & 0 deletions doc/visualization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Visualization

## ECharts

### 折线图

#### 空数据

有时候设置为 0 不一定满足我们的期望
'-' 表示空数据,不被左右数据连接

#### 堆叠

- stack

#### 面积图

- areaStyle

#### 平滑

- smooth: true

#### 阶梯

- step: 'start'

### 富文本

```js
{
label: {
formatter: [
'{style|Customer Text}'
].join('\n'),
rich: {
style: {}
}
}
}
```

### 动画

[过度动画函数](https://echarts.apache.org/handbook/zh/how-to/animation/transition)

## vis.js

```js
// network
import 'vis-network/styles/vis-network.min.css'

// timeline graph2d
import 'vis-timeline/styles/vis-timeline-graph2d.min.css'
```
35 changes: 35 additions & 0 deletions src/api/mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import request from "@/utils/request";

export function postRequest(data: postData) {
return request({
url: "",
method: "post",
data,
});
}

export function getRequest(params: getData) {
return request({
url: "",
method: "get",
params,
});
}

export function getStreamRequest(params: getData) {
return request({
url: "",
method: "get",
params,
responseType: "blob",
timeout: 10 * 1000,
});
}

export function getMock(params: getData) {
return request({
url: "/get-mock-info",
method: "get",
params
});
}
21 changes: 21 additions & 0 deletions src/api/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare interface postData {
name: string
age?: number
}

declare interface getData {
id: number
}

// User
declare interface UserLogIn {
username: string
password: string
}

// Menu
declare interface ResMenu {
name: string
path?: string
parent?: string
}
17 changes: 17 additions & 0 deletions src/api/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import request from "@/utils/request";

export function getUserToken(data: UserLogIn) {
return request({
url: "",
method: "post",
data,
});
}

export function getRequest(params: getData) {
return request({
url: "",
method: "get",
params,
});
}
Loading

0 comments on commit cc744a7

Please sign in to comment.