import api from '../../api/methods';
export default {
    //获取钉钉配置信息
    config(callback){
        api.config().then((data)=>{
            if(data.err_code == 0){
                callback(data.data);
            }
        })
    },
    //通过免签码获取uid
    getSsoToken(code,callback){
        api.getSsoToken({code:code	}).then((data)=>{
            if(data.err_code == 0){
                localStorage.setItem('doc_phone_token',data.data.token);
                alert('保存新token')
                callback();
            }
        })
    },
    //获取微应用免登授权码
    getCode(callback){
        let _this = this;
        this.config((data)=>{
            dd.ready(function() {
                dd.runtime.permission.requestAuthCode({
                    corpId: data.corpId, // 企业id
                    onSuccess: function (info) {
                        // code = info.code // 通过该免登授权码可以获取用户身份
                        _this.getSsoToken(info.code,()=> callback());
                    },
                    onFail: function (info) {
                        alert(JSON.stringify(info))
                        _this.getSsoToken(info.code);
                    },
                });
            });
        })
    },
}