帧视界壹通告,付费看视频的微信小程序
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.

172 lines
3.2 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. function toArray(data) {
  2. if (!data) return []
  3. if (data instanceof Array){
  4. return data
  5. } else {
  6. return [data]
  7. }
  8. }
  9. function generateUUID() {
  10. return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  11. var r = Math.random() * 16 | 0,
  12. v = c == 'x' ? r : (r & 0x3 | 0x8);
  13. return v.toString(16);
  14. });
  15. }
  16. function generateRandomColor() {
  17. const letters = '0123456789ABCDEF';
  18. let color = '#';
  19. for (let i = 0; i < 6; i++) {
  20. color += letters[Math.floor(Math.random() * 16)];
  21. }
  22. return color;
  23. }
  24. function generateLightRandomColor() {
  25. const min = 150;
  26. const range = 105;
  27. const r = Math.floor(Math.random() * range + min);
  28. const g = Math.floor(Math.random() * range + min);
  29. const b = Math.floor(Math.random() * range + min);
  30. const color = 'rgb(' + r + ',' + g + ',' + b + ')';
  31. return color;
  32. }
  33. function verificationAll(data, msg){
  34. if (!msg){
  35. return false
  36. }
  37. if (!data){
  38. uni.showToast({
  39. title: '表单数据未填写',
  40. icon: "none"
  41. })
  42. }
  43. for (let key in msg) {
  44. if (!data[key]) {
  45. uni.showToast({
  46. title: msg[key],
  47. icon: "none"
  48. })
  49. return true
  50. }
  51. }
  52. // let Msgs = {
  53. // default : msg || '表单数据未填写'
  54. // }
  55. // if(typeof msg == 'object'){
  56. // Msgs = {
  57. // default : '表单数据未填写',
  58. // ...msg,
  59. // }
  60. // }
  61. // if (!data){
  62. // uni.showToast({
  63. // title: Msgs.default,
  64. // icon: "none"
  65. // })
  66. // return true
  67. // }
  68. // for (let key in data) {
  69. // if (!data[key] && Msgs[key]) {
  70. // uni.showToast({
  71. // title: Msgs[key],
  72. // icon: "none"
  73. // })
  74. // return true
  75. // }
  76. // }
  77. return false
  78. }
  79. //验证手机号是否合法
  80. function verificationPhone(phone){
  81. if(!/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(phone)){
  82. return false
  83. }
  84. return true
  85. }
  86. //获取url中参数的方法
  87. export function getHrefParams(name) {
  88. var url = window.location.href;
  89. try {
  90. var cs = url.split('?')[1]; //获取?之后的参数字符串
  91. var cs_arr = cs.split('&'); //参数字符串分割为数组
  92. for (var i = 0; i < cs_arr.length; i++) { //遍历数组,拿到json对象
  93. if (cs_arr[i].split('=')[0] == name) {
  94. return cs_arr[i].split('=')[1];
  95. }
  96. }
  97. return "";
  98. } catch {
  99. return "";
  100. }
  101. }
  102. //深度对比合并两个对象,相同属性b会覆盖a
  103. export function deepMergeObject(a, b){
  104. let data = JSON.parse(JSON.stringify(a))
  105. function mergeObject(obj1, obj2){
  106. for(let key in obj2){
  107. if(typeof obj1[key] == 'object'){
  108. obj1[key] = mergeObject(obj1[key], obj2[key])
  109. }else{
  110. obj1[key] = obj2[key]
  111. }
  112. }
  113. return obj1
  114. }
  115. return mergeObject(data, b)
  116. }
  117. function params(url){
  118. if(typeof url == 'object'){
  119. data.url = '/pages' + data.url
  120. return url
  121. }
  122. let data = {
  123. url
  124. }
  125. if(!data.url.includes('/pages')){
  126. data.url = '/pages' + data.url
  127. }
  128. return data
  129. }
  130. export function navigateTo(...args){
  131. uni.navigateTo(params(...args))
  132. }
  133. export function redirectTo(...args){
  134. uni.redirectTo(params(...args))
  135. }
  136. export function navigateBack(num = -1){
  137. uni.navigateBack(num)
  138. }
  139. export default {
  140. toArray,
  141. generateUUID,
  142. verificationAll,
  143. generateRandomColor,
  144. generateLightRandomColor,
  145. verificationPhone,
  146. getHrefParams,
  147. deepMergeObject,
  148. navigateTo,
  149. navigateBack,
  150. redirectTo
  151. }