12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import config from '@/utils/config.js'
- import interfaces from '@/utils/interfaces.js'
- const tools = {
- current_navigator_page_index: 0,
- // 是否登录
- is_login() {
- let user_data = this.get_user_info()
- if(Object.keys(user_data).length === 0 || tools.isNull(user_data.mobile)) {
- return false
- }
- return true
- },
- // 是否登录并进入登录界面
- /*
- * index: -1正常, 1:从AI聊天入口登录 2:从AI画图入口登录
- */
- is_login_gotoLogin(index) {
- if(this.is_login()) {
- return true
- }
- let url = '/pages/login/login'
- if(index > -1) {
- url = '/pages/login/login' +'?index=' + index
- }
- uni.navigateTo({
- url:url
- })
- return false
- },
- // 获取用户信息
- /*
- * 获取let user_data = get_user_info()
- * 使用 user_data.mobile 即可
- */
- get_user_info() {
- return uni.getStorageSync(config.userData)||{}
- },
- // 设置用户信息
- set_user_info(data) {
- uni.setStorageSync(config.userData, data)
- },
-
- // 是否null
- isNull(obj){
- if(obj!=null&&obj!=undefined&&obj!=''&&obj.length!=0){
- return false;
- }
- return true;
- },
-
- // 请求登录
- request_login(that, mobile, password, callback) {
- // 测试账号: 18612220000 18612221111 18612221221 18612221211
- let self = that
- self.request({
- url: interfaces.login,
- data:{'mobile': mobile},
- method:config.post,
- success:(res)=> {
- if(res.code === config.SUCCESS) {
- tools.set_user_info({'mobile': mobile})
- uni.$emit(config.notification.login_state_changed)
- callback(true)
- } else {
- callback(false)
- }
- },
- fail:(e)=> {
- callback(false)
- }
- })
- },
-
- // 请求退出登录
- request_logout(that, callback) {
- uni.showLoading({title:"加载中..."})
- let self = that
- setTimeout(function() {
- tools.set_user_info({})
- uni.$emit(config.notification.login_state_changed)
- uni.$emit(config.notification.switch_page_index, 0)
- callback(true)
- uni.hideLoading()
- }, 1000);
- }
-
- }
- module.exports = tools;
|