import request from '../utils/request.js'
// 退出登录
const logout = function(is, msg = '登录状态已过期，重新登录？') {

	if (is) {
		uni.showModal({
			title: '提示',
			content: msg,
			confirmColor: '#497bff',
			cancelColor: '#606266',
			success: (res) => {
				if (res.confirm) {
					// 清除本地token
					uni.removeStorageSync('token')
					uni.removeStorageSync('user')
					if (this.$store) {
						this.$store.commit('token', '')
						this.$store.commit('user', '')
					}
					// 关闭所有页面返回到登录页
					uni.reLaunch({
						url: '/pages/login/login'
					})
				} else if (res.cancel) {
					console.log('取消');
				}
			}
		});
	} else {
		// 清除本地token
		uni.removeStorageSync('token')
		uni.removeStorageSync('user')
		if (this.$store) {
			this.$store.commit('token', '')
			this.$store.commit('user', '')
		}
		uni.reLaunch({
			url: '/pages/login/login'
		})
	}
}


export default {
	logout,
	request
}
