Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ module.exports = {
plugins: ['prettier', 'import'],
// extends: 'eslint:recommended',
rules: {
'import/order': ['error', {
groups: [
'builtin', // Built-in types are first
'external', // Then the index file
'internal',
]
}],
'import/order': [
'error',
{
groups: [
'builtin', // Built-in types are first
'external', // Then the index file
'internal',
],
},
],
// 非开发模式禁用debugger
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'warn',
// 允许调用首字母大写的函数时没有 new 操作符
Expand Down Expand Up @@ -80,5 +83,4 @@ module.exports = {
'no-undef': 0,
'no-proto': 0,
},

}
};
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
lint:
runs-on: ubuntu-latest
steps:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
Expand All @@ -27,4 +27,4 @@ jobs:
- run: npm install
shell: bash
- name: lint 检查
run: npm run lint
run: npm run lint
89 changes: 44 additions & 45 deletions api/request.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
import config from "../config";

const {baseUrl} = config;
const delay = config.isMock ? 500 : 0
function request(url, method = "GET", data = {}) {
const header = {
"content-type": "application/json"
// 有其他content-type需求加点逻辑判断处理即可
}
// 获取token,有就丢进请求头
const tokenString = wx.getStorageSync("access_token");
if (tokenString) {
header.Authorization = `Bearer ${tokenString}`;
}
return new Promise((resolve, reject) => {
wx.request({
url: baseUrl + url,
method,
data,
dataType: "json", // 微信官方文档中介绍会对数据进行一次JSON.parse
header,
success(res) {
setTimeout(() => {
// HTTP状态码为200才视为成功
if (res.code === 200) {
resolve(res)
} else {
// wx.request的特性,只要有响应就会走success回调,所以在这里判断状态,非200的均视为请求失败
reject(res)
}
}, delay)

},
fail(err) {
setTimeout(() => {
// 断网、服务器挂了都会fail回调,直接reject即可
reject(err)
}, delay)
},
})
})
}

// 导出请求和服务地址
export default request
import config from '../config';

const { baseUrl } = config;
const delay = config.isMock ? 500 : 0;
function request(url, method = 'GET', data = {}) {
const header = {
'content-type': 'application/json',
// 有其他content-type需求加点逻辑判断处理即可
};
// 获取token,有就丢进请求头
const tokenString = wx.getStorageSync('access_token');
if (tokenString) {
header.Authorization = `Bearer ${tokenString}`;
}
return new Promise((resolve, reject) => {
wx.request({
url: baseUrl + url,
method,
data,
dataType: 'json', // 微信官方文档中介绍会对数据进行一次JSON.parse
header,
success(res) {
setTimeout(() => {
// HTTP状态码为200才视为成功
if (res.code === 200) {
resolve(res);
} else {
// wx.request的特性,只要有响应就会走success回调,所以在这里判断状态,非200的均视为请求失败
reject(res);
}
}, delay);
},
fail(err) {
setTimeout(() => {
// 断网、服务器挂了都会fail回调,直接reject即可
reject(err);
}, delay);
},
});
});
}

// 导出请求和服务地址
export default request;
55 changes: 27 additions & 28 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,66 @@
// app.js
import config from './config'
import Mock from './mock/index'
import createBus from './utils/eventBus'
import { connectSocket, fetchUnreadNum } from './services/chat'
import config from './config';
import Mock from './mock/index';
import createBus from './utils/eventBus';
import { connectSocket, fetchUnreadNum } from './services/chat';

if (config.isMock) {
Mock()
Mock();
}

App({
onLaunch() {
const updateManager = wx.getUpdateManager()
const updateManager = wx.getUpdateManager();

updateManager.onCheckForUpdate((res) => {
// console.log(res.hasUpdate)
})
});

updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success(res) {
if (res.confirm) {
updateManager.applyUpdate()
updateManager.applyUpdate();
}
}
})
})
},
});
});

this.getUnreadNum()
this.connect()
this.getUnreadNum();
this.connect();
},
globalData: {
userInfo: null,
unreadNum: 0, // 未读消息数量
socket: null, // SocketTask 对象
unreadNum: 0, // 未读消息数量
socket: null, // SocketTask 对象
},

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

/** 初始化WebSocket */
connect() {
const socket = connectSocket()
const socket = connectSocket();
socket.onMessage((data) => {
data = JSON.parse(data)
if (data.type === 'message' && !data.data.message.read)
this.setUnreadNum(this.globalData.unreadNum + 1)
})
this.globalData.socket = socket
data = JSON.parse(data);
if (data.type === 'message' && !data.data.message.read) this.setUnreadNum(this.globalData.unreadNum + 1);
});
this.globalData.socket = socket;
},

/** 获取未读消息数量 */
getUnreadNum() {
fetchUnreadNum().then(({ data }) => {
this.globalData.unreadNum = data
this.eventBus.emit('unread-num-change', data)
})
this.globalData.unreadNum = data;
this.eventBus.emit('unread-num-change', data);
});
},

/** 设置未读消息数量 */
setUnreadNum(unreadNum) {
this.globalData.unreadNum = unreadNum
this.eventBus.emit('unread-num-change', unreadNum)
}
})
this.globalData.unreadNum = unreadNum;
this.eventBus.emit('unread-num-change', unreadNum);
},
});
12 changes: 4 additions & 8 deletions components/card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ Component({
properties: {
url: String,
desc: String,
tags: Array
tags: Array,
},
data: {

},
methods: {

}
})
data: {},
methods: {},
});
2 changes: 1 addition & 1 deletion components/card/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"t-image": "tdesign-miniprogram/image/image",
"t-tag": "tdesign-miniprogram/tag/tag"
}
}
}
2 changes: 1 addition & 1 deletion components/card/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
gap: 16rpx;
margin-top: 16rpx;
}
}
}
2 changes: 1 addition & 1 deletion components/card/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<t-tag wx:for="{{tags}}" wx:key="index" size="small" variant="light" theme="{{item.theme}}">{{item.text}}</t-tag>
</view>
</view>
</view>
</view>
2 changes: 1 addition & 1 deletion components/nav/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"t-drawer": "tdesign-miniprogram/drawer/drawer",
"t-search": "tdesign-miniprogram/search/search"
}
}
}
4 changes: 2 additions & 2 deletions components/nav/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
width: 375rpx;

.t-icon {
font-size: @font-size-default !important;
font-size: @font-size-default !important;
}
}
}
}
}
12 changes: 6 additions & 6 deletions components/nav/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<view slot="left">
<view class="home-navbar__left">
<t-button bind:touchend="openDrawer" icon="view-list" size="large" variant="text" shape="square" />
<t-search
shape="round"
placeholder="请搜索你想要的内容"
bindtap="searchTurn"
wx:if="{{navType === 'search'}}"
<t-search
shape="round"
placeholder="请搜索你想要的内容"
bindtap="searchTurn"
wx:if="{{navType === 'search'}}"
/>
</view>
</view>
</t-navbar>
<t-drawer visible="{{visible}}" items="{{sidebar}}" placement="left" title="页面目录" bind:item-click="itemClick" />
</view>
</view>
8 changes: 4 additions & 4 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
isMock: true,
baseUrl:''
}
export default {
isMock: true,
baseUrl: '',
};
Loading