博客列表 >vue相关操作

vue相关操作

kiraseo_wwwkiraercom
kiraseo_wwwkiraercom原创
2022年09月08日 23:55:11353浏览

编辑

代码如下

编辑和修改方法

  1. public function save(){
  2. if(Request::isPost()){
  3. $data = Request::param();
  4. //提交值
  5. $datalist = [
  6. 'account'=>$data['account'],
  7. 'name'=>$data['name'],
  8. 'phone'=>$data['phone'],
  9. 'status'=>$data['status'],
  10. 'add_time'=>strtotime($data['add_time']),
  11. 'last_time'=>time(),
  12. ];
  13. //判断了是否有主键
  14. if($data['uid'] !=0){
  15. $datalist['uid'] = $data['uid'];
  16. }else{
  17. $datalist['uid'] = '';
  18. }
  19. //判断是否填写了密码
  20. if(!empty($data['password'])){
  21. $datalist['password']=md5($data['password']);
  22. }else{
  23. $list= Db::table('bew_users')->field('password')->where(['uid'=>$data['uid']])->find();
  24. $datalist['password'] = $list['password'];
  25. }
  26. //修改与提交方法
  27. $res = Db::name('bew_users')->save($datalist);
  28. if (!empty($res)){
  29. $rest = ['code'=>0,'msg'=>"操作成功"];
  30. }else{
  31. $rest = ['code'=>1,'msg'=>"操作失败"];
  32. }
  33. echo json_encode($rest);
  34. }
  35. }
  36. `
  1. const fun = ()=>{
  2. console.log(fromData);
  3. Save(fromData).then( (e)=>{
  4. if(e.code == 0){
  5. ElMessage({
  6. message: e.msg,
  7. type: 'success'
  8. });
  9. }else{
  10. ElMessage({
  11. message: e.msg,
  12. type: 'error'
  13. });
  14. }
  15. console.log(e);
  16. } )
  17. //刷新页面
  18. // location.reload();
  19. getHome().then(res=>{
  20. console.log(res);
  21. tableData.lists = res;
  22. })
  23. data.is_form= false;
  24. }

效果如下

编辑前.jpg
编辑后.jpg

删除操作

代码如下

  1. //删除方法
  2. public function del(){
  3. if(Request::isPost()){
  4. $uid = Request::param();
  5. if(empty($uid['uid'])){
  6. $rest = ['code'=>1,'msg'=>"操作失败"];
  7. echo json_encode($rest);
  8. exit;
  9. }
  10. $del = Db::name('bew_users')->where('uid', $uid['uid'])->update(['status' => 0]);
  11. if (!empty($del)){
  12. $rest = ['code'=>0,'msg'=>"操作成功"];
  13. echo json_encode($rest);
  14. }else{
  15. $rest = ['code'=>1,'msg'=>"操作失败"];
  16. echo json_encode($rest);
  17. exit;
  18. }
  19. }
  20. }
  1. const del = (e)=>{
  2. console.log(e.uid);
  3. Del({uid:e.uid}).then(e =>{
  4. console.log(e.code);
  5. console.log(e.msg);
  6. if(e.code == 0){
  7. ElMessage({
  8. message: e.msg,
  9. type: 'success'
  10. });
  11. }else{
  12. ElMessage({
  13. message: e.msg,
  14. type: 'error'
  15. });
  16. }
  17. getHome().then(res=>{
  18. console.log(res);
  19. tableData.lists = res;
  20. })
  21. })
  22. }

效果如下

删除前.jpg
删除后.jpg

登录操作与token加密

php代码如下

  1. //登录方法
  2. public function login(){
  3. if(Request::isPost()){
  4. $data =Request::param();
  5. if(empty($data['account'])){
  6. $rest = ['code'=>1,'msg'=>"用户名不能为空"];
  7. echo json_encode($rest);
  8. exit;
  9. }
  10. if(empty($data['password'])){
  11. $rest = ['code'=>1,'msg'=>"密码必须输入"];
  12. echo json_encode($rest);
  13. exit;
  14. }
  15. $user = Db::name('bew_users')->field('uid,name,password')->where(['account'=>$data['account']])->find();
  16. if(!empty($user)){
  17. if($user['password']== md5($data['password'])){
  18. //使用token加密方式
  19. $ticket = Ticket::create($user['uid'],'phpcn');
  20. $user['ticket'] = $ticket;
  21. unset($user['password'],$user['uid']);
  22. $rest = ['code'=>0,'data'=>$user,'msg'=>"登录成功"];
  23. echo json_encode($rest);
  24. }else{
  25. $rest = ['code'=>1,'msg'=>"密码错误"];
  26. echo json_encode($rest);
  27. exit;
  28. }
  29. }else{
  30. $rest = ['code'=>1,'msg'=>"用户不存在"];
  31. echo json_encode($rest);
  32. exit;
  33. }
  34. }
  35. }
  1. //引入文件
  2. import {Login} from '../network/admin.js';
  3. const ticket = window.localStorage.getItem("ticket");
  4. //写判断
  5. if(ticket){
  6. ElMessage({
  7. message: '您已登录',
  8. type: 'success'
  9. });
  10. router.push("/");
  11. }
  12. const onSubmit = ()=>{
  13. Login(state).then( (e)=>{
  14. console.log(e.data);
  15. if(e.code == 0){
  16. ElMessage({
  17. message: e.msg,
  18. type: 'success'
  19. });
  20. // 登录完成以后
  21. window.localStorage.setItem("ticket",e.data.ticket);
  22. window.localStorage.setItem("name",e.data.name);
  23. router.push("/");
  24. }else{
  25. ElMessage({
  26. message: e.msg,
  27. type: 'error'
  28. });
  29. }
  30. } )
  31. }

最后效果如下(写上登录用户名)

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议