Skip to content

Commit c2c7652

Browse files
authored
fix: format (#27)
1 parent a6f014c commit c2c7652

65 files changed

Lines changed: 9548 additions & 8782 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ module.exports = {
2727
plugins: ['prettier', 'import'],
2828
// extends: 'eslint:recommended',
2929
rules: {
30-
'import/order': ['error', {
31-
groups: [
32-
'builtin', // Built-in types are first
33-
'external', // Then the index file
34-
'internal',
35-
]
36-
}],
30+
'import/order': [
31+
'error',
32+
{
33+
groups: [
34+
'builtin', // Built-in types are first
35+
'external', // Then the index file
36+
'internal',
37+
],
38+
},
39+
],
3740
// 非开发模式禁用debugger
3841
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'warn',
3942
// 允许调用首字母大写的函数时没有 new 操作符
@@ -80,5 +83,4 @@ module.exports = {
8083
'no-undef': 0,
8184
'no-proto': 0,
8285
},
83-
84-
}
86+
};

.github/workflows/pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
lint:
1010
runs-on: ubuntu-latest
11-
steps:
11+
steps:
1212
- uses: actions/checkout@v2
1313
- uses: actions/setup-node@v2
1414
with:
@@ -27,4 +27,4 @@ jobs:
2727
- run: npm install
2828
shell: bash
2929
- name: lint 检查
30-
run: npm run lint
30+
run: npm run lint

api/request.js

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
1-
import config from "../config";
2-
3-
const {baseUrl} = config;
4-
const delay = config.isMock ? 500 : 0
5-
function request(url, method = "GET", data = {}) {
6-
const header = {
7-
"content-type": "application/json"
8-
// 有其他content-type需求加点逻辑判断处理即可
9-
}
10-
// 获取token,有就丢进请求头
11-
const tokenString = wx.getStorageSync("access_token");
12-
if (tokenString) {
13-
header.Authorization = `Bearer ${tokenString}`;
14-
}
15-
return new Promise((resolve, reject) => {
16-
wx.request({
17-
url: baseUrl + url,
18-
method,
19-
data,
20-
dataType: "json", // 微信官方文档中介绍会对数据进行一次JSON.parse
21-
header,
22-
success(res) {
23-
setTimeout(() => {
24-
// HTTP状态码为200才视为成功
25-
if (res.code === 200) {
26-
resolve(res)
27-
} else {
28-
// wx.request的特性,只要有响应就会走success回调,所以在这里判断状态,非200的均视为请求失败
29-
reject(res)
30-
}
31-
}, delay)
32-
33-
},
34-
fail(err) {
35-
setTimeout(() => {
36-
// 断网、服务器挂了都会fail回调,直接reject即可
37-
reject(err)
38-
}, delay)
39-
},
40-
})
41-
})
42-
}
43-
44-
// 导出请求和服务地址
45-
export default request
1+
import config from '../config';
2+
3+
const { baseUrl } = config;
4+
const delay = config.isMock ? 500 : 0;
5+
function request(url, method = 'GET', data = {}) {
6+
const header = {
7+
'content-type': 'application/json',
8+
// 有其他content-type需求加点逻辑判断处理即可
9+
};
10+
// 获取token,有就丢进请求头
11+
const tokenString = wx.getStorageSync('access_token');
12+
if (tokenString) {
13+
header.Authorization = `Bearer ${tokenString}`;
14+
}
15+
return new Promise((resolve, reject) => {
16+
wx.request({
17+
url: baseUrl + url,
18+
method,
19+
data,
20+
dataType: 'json', // 微信官方文档中介绍会对数据进行一次JSON.parse
21+
header,
22+
success(res) {
23+
setTimeout(() => {
24+
// HTTP状态码为200才视为成功
25+
if (res.code === 200) {
26+
resolve(res);
27+
} else {
28+
// wx.request的特性,只要有响应就会走success回调,所以在这里判断状态,非200的均视为请求失败
29+
reject(res);
30+
}
31+
}, delay);
32+
},
33+
fail(err) {
34+
setTimeout(() => {
35+
// 断网、服务器挂了都会fail回调,直接reject即可
36+
reject(err);
37+
}, delay);
38+
},
39+
});
40+
});
41+
}
42+
43+
// 导出请求和服务地址
44+
export default request;

app.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,66 @@
11
// app.js
2-
import config from './config'
3-
import Mock from './mock/index'
4-
import createBus from './utils/eventBus'
5-
import { connectSocket, fetchUnreadNum } from './services/chat'
2+
import config from './config';
3+
import Mock from './mock/index';
4+
import createBus from './utils/eventBus';
5+
import { connectSocket, fetchUnreadNum } from './services/chat';
66

77
if (config.isMock) {
8-
Mock()
8+
Mock();
99
}
1010

1111
App({
1212
onLaunch() {
13-
const updateManager = wx.getUpdateManager()
13+
const updateManager = wx.getUpdateManager();
1414

1515
updateManager.onCheckForUpdate((res) => {
1616
// console.log(res.hasUpdate)
17-
})
17+
});
1818

1919
updateManager.onUpdateReady(() => {
2020
wx.showModal({
2121
title: '更新提示',
2222
content: '新版本已经准备好,是否重启应用?',
2323
success(res) {
2424
if (res.confirm) {
25-
updateManager.applyUpdate()
25+
updateManager.applyUpdate();
2626
}
27-
}
28-
})
29-
})
27+
},
28+
});
29+
});
3030

31-
this.getUnreadNum()
32-
this.connect()
31+
this.getUnreadNum();
32+
this.connect();
3333
},
3434
globalData: {
3535
userInfo: null,
36-
unreadNum: 0, // 未读消息数量
37-
socket: null, // SocketTask 对象
36+
unreadNum: 0, // 未读消息数量
37+
socket: null, // SocketTask 对象
3838
},
3939

4040
/** 全局事件总线 */
4141
eventBus: createBus(),
4242

4343
/** 初始化WebSocket */
4444
connect() {
45-
const socket = connectSocket()
45+
const socket = connectSocket();
4646
socket.onMessage((data) => {
47-
data = JSON.parse(data)
48-
if (data.type === 'message' && !data.data.message.read)
49-
this.setUnreadNum(this.globalData.unreadNum + 1)
50-
})
51-
this.globalData.socket = socket
47+
data = JSON.parse(data);
48+
if (data.type === 'message' && !data.data.message.read) this.setUnreadNum(this.globalData.unreadNum + 1);
49+
});
50+
this.globalData.socket = socket;
5251
},
5352

5453
/** 获取未读消息数量 */
5554
getUnreadNum() {
5655
fetchUnreadNum().then(({ data }) => {
57-
this.globalData.unreadNum = data
58-
this.eventBus.emit('unread-num-change', data)
59-
})
56+
this.globalData.unreadNum = data;
57+
this.eventBus.emit('unread-num-change', data);
58+
});
6059
},
6160

6261
/** 设置未读消息数量 */
6362
setUnreadNum(unreadNum) {
64-
this.globalData.unreadNum = unreadNum
65-
this.eventBus.emit('unread-num-change', unreadNum)
66-
}
67-
})
63+
this.globalData.unreadNum = unreadNum;
64+
this.eventBus.emit('unread-num-change', unreadNum);
65+
},
66+
});

components/card/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ Component({
22
properties: {
33
url: String,
44
desc: String,
5-
tags: Array
5+
tags: Array,
66
},
7-
data: {
8-
9-
},
10-
methods: {
11-
12-
}
13-
})
7+
data: {},
8+
methods: {},
9+
});

components/card/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"t-image": "tdesign-miniprogram/image/image",
55
"t-tag": "tdesign-miniprogram/tag/tag"
66
}
7-
}
7+
}

components/card/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
gap: 16rpx;
2525
margin-top: 16rpx;
2626
}
27-
}
27+
}

components/card/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
<t-tag wx:for="{{tags}}" wx:key="index" size="small" variant="light" theme="{{item.theme}}">{{item.text}}</t-tag>
77
</view>
88
</view>
9-
</view>
9+
</view>

components/nav/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"t-drawer": "tdesign-miniprogram/drawer/drawer",
77
"t-search": "tdesign-miniprogram/search/search"
88
}
9-
}
9+
}

components/nav/index.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
width: 375rpx;
2222

2323
.t-icon {
24-
font-size: @font-size-default !important;
24+
font-size: @font-size-default !important;
2525
}
2626
}
2727
}
28-
}
28+
}

0 commit comments

Comments
 (0)