You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.1 KiB

3 years ago
  1. import {request} from '@/common/js/request'
  2. export default{
  3. data(){
  4. return {
  5. page: 0, //页码
  6. pageNum: 6, //每页加载数据量
  7. loadingType: 1, //0加载前 1加载中 2没有更多
  8. isLoading: false, //刷新数据
  9. loaded: false, //加载完毕
  10. }
  11. },
  12. methods: {
  13. log(data){
  14. console.log(JSON.parse(JSON.stringify(data)))
  15. },
  16. /**
  17. * navigatorTo跳转页面
  18. * @param {String} url
  19. * @param {Object} options
  20. * @param {Boolean} options.login 是否检测登录
  21. */
  22. navTo(url, options={}){
  23. this.$util.throttle(()=>{
  24. if(!url){
  25. return;
  26. }
  27. if((~url.indexOf('login=1') || options.login) && !this.$store.getters.hasLogin){
  28. url = '/pages/auth/login';
  29. }
  30. uni.navigateTo({
  31. url
  32. })
  33. }, 300)
  34. },
  35. /**
  36. * $request云函数请求
  37. * @param {String} module
  38. * @param {String} operation
  39. * @param {Boolean} data 请求参数
  40. * @param {Boolean} ext 附加参数
  41. * @param {Boolean} ext.showLoading 是否显示loading状态默认不显示
  42. * @param {Boolean} ext.hideLoading 是否关闭loading状态默认关闭
  43. * @param {Boolean} ext.login 未登录拦截
  44. * @param {Boolean} ext.setLoaded 加载完成是设置页面加载完毕
  45. */
  46. $request(module, operation, data={}, ext={}){
  47. if(ext.login && !this.$util.isLogin()){
  48. return;
  49. }
  50. if(ext.showLoading){
  51. this.isLoading = true;
  52. }
  53. return new Promise((resolve, reject)=> {
  54. request(module, operation, data, ext).then(result => {
  55. if(ext.hideLoading !== false){
  56. this.isLoading = false;
  57. }
  58. setTimeout(()=>{
  59. if(this.setLoaded !== false){
  60. this.loaded = true;
  61. }
  62. }, 100)
  63. this.$refs.confirmBtn && this.$refs.confirmBtn.stop();
  64. resolve(result);
  65. }).catch((err) => {
  66. reject(err);
  67. })
  68. })
  69. },
  70. imageOnLoad(data, key){
  71. setTimeout(()=>{
  72. this.$set(data, 'loaded', true);
  73. }, 100)
  74. },
  75. showPopup(key){
  76. this.$util.throttle(()=>{
  77. this.$refs[key].open();
  78. }, 200)
  79. },
  80. hidePopup(key){
  81. this.$refs[key].close();
  82. },
  83. stopPrevent(){},
  84. },
  85. }