耀实惠小程序
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.

89 lines
2.0 KiB

  1. var config = require('./config.js');
  2. import MD5G from './md5utf-8.js';
  3. //排序的函数
  4. function objKeySort(arys) {
  5. var newkey = Object.keys(arys).sort();
  6. var newObj = {};
  7. for (var i = 0; i < newkey.length; i++) {
  8. newObj[newkey[i]] = arys[newkey[i]];
  9. }
  10. return newObj; //返回排好序的新对象
  11. }
  12. //转换为json字符串
  13. function Jsonstr(data){
  14. var obj = {};
  15. for (var key in data) {
  16. obj[key] = data[key]
  17. }
  18. return JSON.stringify(obj);
  19. }
  20. //api签名
  21. function getSign(params) {
  22. var str = '';
  23. var sortparams = objKeySort(params);
  24. for (var p in sortparams) {
  25. if (params[p] != '') {
  26. str += p + '=' + params[p] + '&';
  27. }
  28. }
  29. str = str + config.ACCESS;
  30. str = MD5G.md5(str);
  31. return str.toLowerCase();
  32. }
  33. function showLoading(){
  34. uni.showLoading({
  35. title: '加载中...',
  36. duration: 10000
  37. });
  38. }
  39. function hideLoading(){
  40. uni.hideLoading();
  41. }
  42. function showToast(title){
  43. uni.showToast({
  44. title: title,
  45. icon: "none",
  46. duration: 2000,
  47. mask:false
  48. })
  49. }
  50. function showToastSuccess(title){
  51. uni.showToast({
  52. title: title,
  53. icon: "success",
  54. duration: 2000,
  55. mask:false
  56. })
  57. }
  58. function Urlencode(str) {
  59. str = (str + '').toString();
  60. return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
  61. replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
  62. }
  63. function GetUrlKey(name){
  64. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
  65. }
  66. /**
  67. * 是否存在字符
  68. * @param {Object} value
  69. */
  70. function isExist(value) {
  71. if (value !== null && value !== undefined && value !== "undefined" && value !== "null" && value.length > 0) {
  72. return true;
  73. } else {
  74. return false;
  75. }
  76. }
  77. export default {
  78. getSign:getSign,
  79. showToast:showToast,
  80. showLoading:showLoading,
  81. hideLoading:hideLoading,
  82. showToastSuccess:showToastSuccess,
  83. Urlencode:Urlencode,
  84. GetUrlKey:GetUrlKey,
  85. isExist:isExist
  86. }