一、后端api开放路由
在根目录下route文件夹下app.php文件中,在perimission的group中添加如下代码:
Route::get('member/personal_log','permission.Member/personalLog');// 获取个人信息操作接口
二、后端api添加方法
在根目录下app文件夹下controller文件夹下permission文件夹下Member.php文件中,添加如下代码:
/**
* 个人今日操作记录
* User: 龙哥·三年风水
* Date: 2024/12/13
* Time: 11:24
* @ return \think\response\Json
*/
public function personalLog(){
$param = $this->request->param();
$where[] = ['admin_id', '=', $this->userId];
$where[] = ['create_time', '=', date('Y-m-d',time())];
$resList = TokenModel::dataList($where, 'id,token_type,menu_name,login_time', [$param['currentPage'], $param['currentSize']],'login_time DESC');
$list = $resList['info'];
foreach($list as $k=>$v){
$list[$k]['title'] = PMModel::menunameTitle($v['menu_name']);
$list[$k]['token_log'] = TokenModel::tokenType($v['token_type']);
unset($list[$k]['token_type']);
unset($list[$k]['menu_name']);
}
$res['list'] = $list;
$res['meat'] = $resList['page'];
return succ('操作成功',$res);
}
在根目录下app文件夹下model文件夹下common文件夹下Token.php文件中添加如下方法:
/**
* 返回类型属性
* User: 龙哥·三年风水
* Date: 2024/12/13
* Time: 11:22
* @ param $tokenType 类型编号
* @ return mixed
*/
public static function tokenType($tokenType){
$arr = ["","登录","退出","自动退出","列表","所有","详情","保存","启禁用","删除","获取个人资料","修改个人资料","获取菜单权限","上传文件"];
return $arr[$tokenType];
}
在根目录下app文件夹下model文件夹下permission文件夹下Menu.php文件中添加如下代码:
//向上级找菜单名称
public static function menunameTitle($menuname){
$pid = self::dataFinds(self::$name, ['menuname' => $menuname], 'pid', false, self::$connection);
if(empty($pid))return "";
$ids = [];
if($pid != 0){
self::recursionsUpward(self::$name, ['id' => $pid], 'pid', self::$connection, $ids);
}
array_push($ids,$pid);
$titles = '';
foreach ($ids as $k=>$v){
$titles .= self::dataFinds(self::$name, ['id' => $v], 'title', false, self::$connection).'-';
}
return $titles;
}
三、前端页面展示登录日志功能
在根目录下src文件夹下views文件夹下profile文件夹下components文件夹下Timeline.vue中,添加如下代码:
<template>
<div class="block">
<el-timeline>
<el-timeline-item v-for="item of list" :key="item.id" :timestamp="item.login_time" placement="top">
<el-card>
<h4>{{ item.title }}{{ item.token_log }}</h4>
</el-card>
</el-timeline-item>
</el-timeline>
<div class="block">
<el-pagination
:hide-on-single-page="true"
:current-page="currentPage"
:page-sizes="pageSizes"
:page-size="currentSize"
layout="total, sizes, prev, pager, next, jumper"
:total="dataTotal"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</div>
</template>
<script>
import { getList } from '@/api/common'
export default {
data() {
return {
list: [],
pageSizes: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500],
currentPage: 1, // 当前页数
currentSize: 10, // 每页条数
dataTotal: 0, // 总数据
}
},
// 初始化执行的
created() {
this.getList()// 获取管理员数据
},
// 所有的方法都需要放到这个里面
methods: {
// 管理员数据 --异步
async getList(page = 0) {
const params = {
currentPage: page === 0 ? this.currentPage : page,
currentSize: this.currentSize,
}
await getList(params).then(res => {
this.list = res.data.list
this.dataTotal = res.data.meat.total * 1
})
},
// 每页条数切换
handleSizeChange(val) {
this.currentSize = val
this.getList()
},
// 页数切换
handleCurrentChange(val) {
this.currentPage = val
this.getList()
}
}
}
</script>
四、提前说明
明天将完成操作日志功能