params.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import router from '../router/index';
  2. import GET from '@/utils/tool/GET';
  3. export default {
  4. onLoad(params){
  5. // 执行解析目录
  6. try {
  7. this.name = this.__route__.split('/').pop();
  8. } catch (e) {
  9. console.error('catch fail ---> name',this.__route__);
  10. this.name = this.__route__;
  11. }
  12. // 制作 params 列表
  13. this.$params = Object.assign(params, params.query) || {};
  14. this.$storage_params = Object.assign({},this.$params);
  15. this.$memoryParams = router.memoryGet(this.name) || {};
  16. // 执行解析
  17. for (let key in this.$params) {
  18. if (this.$params.hasOwnProperty(key) && typeof this.$params[key]==='string' && this.$params[key].indexOf('{') === 0) {
  19. try {
  20. this.$params[key] = JSON.parse(this.$params[key]);
  21. } catch (e) {
  22. }
  23. }
  24. }
  25. // 解析针对 直播跳转商品详情 custom_params 执行合并
  26. if (this.$params['custom_params']) {
  27. let useCustomParams = decodeURIComponent(decodeURIComponent(this.$params['custom_params']));
  28. try {
  29. this.$params['custom_params'] = JSON.parse(useCustomParams);
  30. this.$params = Object.assign(this.$params,this.$params['custom_params']);
  31. } catch (e) {
  32. this.$params['custom_params'] = useCustomParams;
  33. }
  34. }
  35. let scene = {};
  36. /* 如果存在扫码等情况进入获取参数列表 */
  37. this.$params.scene && GET.decode(this.$params.scene,(key,value)=>{
  38. this.$params[key] = value;
  39. });
  40. if (params.scene) {
  41. this.$params['scene_encode_string'] = params.scene;
  42. this.$params['scene'] = scene;
  43. }
  44. for (let key in this.$params) {
  45. if (this.$params.hasOwnProperty(key) && typeof this.$params[key] === 'string') {
  46. this.$params[key] = decodeURIComponent(this.$params[key]);
  47. }
  48. }
  49. },
  50. created(){
  51. this.$params = {};
  52. }
  53. }