user.js 1.01 KB
import Taro from '@tarojs/taro';
import {login as LoginModel} from '../models';

export default {
    getYHStorageSync(key, fromPage) {
		// 本地缓存
        try {
          	return Taro.getStorageSync(key);
        } catch (e) {
			Taro.reportAnalytics('get_storage_error', {
				key: key,
				error: e.message,
				error_code: e.code,
				from_page: fromPage,
			});
          	return null;
        }
	},
	
	// 根据unionId上传微信头像昵称.
	sendWeChatUserDataWithUnionId(unionId, nickName, userAvatarUrl) {
		if (!unionId || !nickName || !userAvatarUrl || userAvatarUrl == "images/mine_default_head.png") return;

		LoginModel.addUnionUpdUser({
			unionId: unionId,
			headIco: userAvatarUrl,
			nickname: nickName
		});
	},

	// 根据uid上传微信头像昵称
	sendWeChatUserData(uid, nickName, userAvatarUrl) {
		if (!uid || !nickName || !userAvatarUrl || userAvatarUrl == "images/mine_default_head.png") return;

		LoginModel.addUpdUser({
			uid: uid,
			headIco: userAvatarUrl,
			nickname: nickName
		});
	}
}