PHP项目学习笔记-萤火商城-前后台判断是否登录

如何在uniapp页面增加是否登录的判断

后台判断代码,在方法中直接加入代码

    public function docterList()
    {
        $userInfo = $this->getLoginUser();
        if (!$userInfo) {
            $this->error = '未登录,请登录';
            return false;
        }

        $list = [
            [
                "docterName" => "王医生 【副主任医师 10年】",
                "index" => 1,
                "faceurl" => "http://127.0.0.1/uploads/10001/20231018/e37702ac8171c2b532ef98b5dec802fb.jpg",
                "docterDetail" => "123123123"
            ],
            [
                "docterName" => "谢医生 【副主任医师 10年】】",
                "index" => 2,
                "faceurl" => "http://127.0.0.1/uploads/10001/20231018/e37702ac8171c2b532ef98b5dec802fb.jpg",
                "docterDetail" => "56456456456"
            ],
            [
                "docterName" => "赵医生 【副主任医师 10年】",
                "index" => 3,
                "faceurl" => "http://127.0.0.1/uploads/10001/20231018/e37702ac8171c2b532ef98b5dec802fb.jpg",
                "docterDetail" => "789789789789"
            ]
        ];
        return $this->renderSuccess(compact('list'));
    }

前台代码

import store from '@/store'
import * as UserApi from '@/api/user'
import {
	checkLogin
} from '@/core/app'

getMyDocterLists() {
	const app = this
	return new Promise((resolve, reject) => {
		// 判断是否已登录
		app.isLogin = checkLogin()
		//这句的意思是如果没有登录,就没有数据,就不会发送请求
		// !app.isLogin ? resolve(null) : ReservationApi.docterList({}, {

		//这里是直接请求接口,如果返回结果是未登录,就会弹出弹窗提示
		ReservationApi.docterList({}, {
				load: app.isFirstload
			})
			.then(result => {
				app.docterList = result.data.list
				resolve(app.docterList)
			})
			.catch(err => {
				if (err.result && err.result.status == 401) {
					app.isLogin = false
					resolve(null)
				} else {
					reject(err)
				}
			})
	})
},

你可能感兴趣的:(二开笔记,php,php,学习,笔记)