Auth.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const template=`
  2. <slot v-if="isPermit()"></slot>
  3. `;
  4. import {inArray} from '../util.js';
  5. export default {
  6. name: "Auth",
  7. data: function () {
  8. return {
  9. _controller:'',
  10. }
  11. },
  12. props: {
  13. controller: {
  14. type:String,
  15. default:''
  16. },
  17. action: {
  18. type:String,
  19. default:''
  20. },
  21. admin_id:{
  22. type:Array,
  23. default:[]
  24. },
  25. group_id: {
  26. type:Array,
  27. default:[]
  28. }
  29. },
  30. mounted:function (){
  31. this._controller=this.controller.replaceAll('\\\\','\\');
  32. },
  33. template:template,
  34. methods:{
  35. isPermit:function (){
  36. let b1=false,b2=false,b3 = false;
  37. if(this._controller && this.action){
  38. b1=Yunqi.auth.check(this._controller,this.action);
  39. }
  40. if(this.admin_id.length>0){
  41. b2 = inArray(this.admin_id,Yunqi.auth.admin.id);
  42. }
  43. if(this.group_id.length>0){
  44. for(let i=0;i<Yunqi.auth.admin.groupids.length;i++){
  45. b3=inArray(this.group_id,Yunqi.auth.admin.groupids[i]);
  46. if(b3) break;
  47. }
  48. }
  49. return b1 || b2 || b3;
  50. }
  51. }
  52. };