index.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import moment from 'moment';
  2. const assetsUrl="https://zhenyanapp-gen.oss-cn-qingdao.aliyuncs.com/wechat-mini-pro/";
  3. const IMSDKCode=1400293452;
  4. //const IMSDKCode=1400456480;
  5. //const apiHost = 'http://192.168.1.253:8080' //本地;
  6. const apiHost = 'https://mini.sugarpark.cn'
  7. //const apiHost = 'http://jliao-api2-svc-test.internal.jiebide.xin'
  8. const protocal={
  9. behaviorStandar:'https://h5.sugarpark.cn/agreement/behavior-standard.html',
  10. userAgreement:'https://h5.sugarpark.cn/agreement/user-agreement.html',
  11. privacy:'https://h5.sugarpark.cn/agreement/privacy.html',
  12. addedService:'https://h5.sugarpark.cn/agreement/added-service.html'
  13. }
  14. const getApiHost=()=>{
  15. return apiHost;
  16. }
  17. const showMsg = msg => {
  18. uni.showToast({
  19. title: msg,
  20. icon: 'none',
  21. mask: true
  22. });
  23. }
  24. const hasSafeArea = () => {
  25. let result = uni.getSystemInfoSync();
  26. let sWidth = result.screenWidth * result.pixelRatio,
  27. sHeight = result.screenHeight * result.pixelRatio;
  28. if (result.model.indexOf('iPhone') == -1) {
  29. return false;
  30. } else if (sWidth == 1125 && sHeight == 2436) {
  31. return true;
  32. } else if (sWidth == 828 && sHeight == 1792) {
  33. return true;
  34. } else if (sWidth == 1170 && sHeight == 2532) {
  35. return true;
  36. } else if (sWidth == 1242 && sHeight == 2688) {
  37. return true;
  38. } else if (sWidth == 1284 && sHeight == 2778) {
  39. return true;
  40. }
  41. return false
  42. }
  43. const timeFn = (dateBeginTime, dateEndTime) => {
  44. var timeFn;
  45. var dateDiff = dateEndTime - dateBeginTime; //时间差的毫秒数
  46. var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
  47. var leave1 = dateDiff % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
  48. var hours = Math.floor(leave1 / (3600 * 1000)) //计算出小时数
  49. //计算相差分钟数
  50. var leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数
  51. var minutes = Math.floor(leave2 / (60 * 1000)) //计算相差分钟数
  52. //计算相差秒数
  53. var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
  54. var seconds = Math.round(leave3 / 1000)
  55. var timeFn = dayDiff + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒";
  56. return timeFn;
  57. }
  58. const checkPhone = (phone) => { //手机号码
  59. let reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
  60. if(phone.substr(0,3)==='120'&&phone.length===11){
  61. return true;
  62. }
  63. if (reg.test(phone)) {
  64. return true;
  65. } else {
  66. return false;
  67. }
  68. }
  69. const checkTel = (tel) => { //座机号码不支持分机
  70. return /0\d{2,3}-\d{7,8}/.test(tel)
  71. }
  72. const checkIdNo = (idNo) => {
  73. return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idNo)
  74. }
  75. const checkChinese = (str) => {
  76. return /^[\u4e00-\u9fa5]+$/.test(str)
  77. }
  78. const compare = (property) => {
  79. return (a, b) => {
  80. var value1 = a[property];
  81. var value2 = b[property];
  82. return value1 - value2;
  83. }
  84. }
  85. const request = (url, method, data) => {
  86. return new Promise((resolve, reject) => {
  87. if (method === undefined) {
  88. method = 'GET';
  89. }
  90. let deviceConfig=uni.getSystemInfoSync();
  91. let LL_Ukn =uni.getStorageSync('LL_Ukn')||"szxe/TwE/wNJxcF+51069Dw3KHJQmbEuE2tEVHG4ETQ1TEnZ6loF7MQdmCFePTWTS9NE8zhDBrvPplTUYNnlPa10jJ1GycLQjpe2CkO+UvflA8adpe/uD5z2C8Bp1Pg9cThzHmqxeAe1Oq9G1eo3PKfGGYLALGx+dgFPYMn06M/Y+lVio4WpXbNW8KMNkWyxnFZnpZEXzzyDUCT13TMF9tevVJ9/Sb3yBgLiLYnydplax+zjkFqwGSiDrQWR/E8s";
  92. let LL_Csi=uni.getStorageSync('LL_Csi')||{
  93. av:"2.6.0",
  94. brand:"Apple",
  95. currTime:1654149186191,
  96. deviceCode:deviceConfig.deviceId,
  97. iOS:{"idfa":"00000000-0000-0000-0000-000000000000"},
  98. lang:"zh","model":"iPhone12,5","ov":"15.3.1",
  99. pkgCate:"JyPark",
  100. platform:"WechatMP",
  101. resolution:{"h":2688,"s":3,"w":1242},
  102. appId:15,
  103. android:{market:'Unknown'}
  104. };
  105. let token= uni.getStorageSync('token')||"88b99b11d3fc4cc3a71959b824678ce8";
  106. uni.request({
  107. url: `${apiHost}${url}`,
  108. method: method,
  109. data: data,
  110. header: {
  111. 'Content-Type': 'application/json',
  112. // 'token': url === ('/cufd') ? '' : token,
  113. // 'LL_Ukn': url === ('/cufd') ? '' : LL_Ukn,
  114. // 'LL_Csi':url === ('/cufd') ? '' : JSON.stringify(LL_Csi),
  115. 'token': url === 'userLogin/login' ? '' : token,
  116. 'LL_Ukn': LL_Ukn,
  117. 'LL_Csi': JSON.stringify(LL_Csi),
  118. },
  119. success: res => {
  120. if (res.data.status === 'Unauthorized') {
  121. uni.setStorageSync('token','');
  122. }
  123. else if(res.data.status === 'FrozenUser'){
  124. // 用户异常
  125. uni.showToast({
  126. icon:'none',
  127. title:"用户已被冻结"
  128. })
  129. setTimeout(()=>{
  130. uni.reLaunch({
  131. url:'/pages/login/login'
  132. })
  133. },2000)
  134. }
  135. else if(res.data.status=== 'Fail'){
  136. // 用户异常
  137. uni.showToast({
  138. icon:'none',
  139. title:res.data.msg
  140. })
  141. setTimeout(()=>{
  142. uni.reLaunch({
  143. url:'/pages/login/login'
  144. })
  145. },2000)
  146. }
  147. else if(res.data.status=== 'Exception'){
  148. // 自动登录异常
  149. uni.showToast({
  150. icon:'none',
  151. title:res.data.msg
  152. })
  153. }
  154. else if(res.data.status==='Succ'||res.data.code===0){
  155. resolve(res.data)
  156. }
  157. else{
  158. reject(res.data)
  159. }
  160. },
  161. fail: res => reject(res.data),
  162. complete: res => {}
  163. });
  164. });
  165. }
  166. const get = (url) => {
  167. return new Promise((resolve,reject)=>{
  168. uni.request({
  169. url:url,
  170. method:'GET',
  171. header:{'Access-Control-Allow-Origin':'*'},
  172. success:res=>{
  173. return res.data
  174. }
  175. })
  176. })
  177. }
  178. // const upload = (url, path) => {
  179. // return new Promise((resolve, reject) => {
  180. // let LL_Ukn =uni.getStorageSync('LL_Ukn')||"szxe/TwE/wNJxcF+51069Dw3KHJQmbEuE2tEVHG4ETQ1TEnZ6loF7MQdmCFePTWTS9NE8zhDBrvPplTUYNnlPa10jJ1GycLQjpe2CkO+UvflA8adpe/uD5z2C8Bp1Pg9cThzHmqxeAe1Oq9G1eo3PKfGGYLALGx+dgFPYMn06M/Y+lVio4WpXbNW8KMNkWyxnFZnpZEXzzyDUCT13TMF9tevVJ9/Sb3yBgLiLYnydplax+zjkFqwGSiDrQWR/E8s";
  181. // let LL_Csi=uni.getStorageSync('LL_Csi')||{
  182. // av:"2.6.0",
  183. // brand:"Apple",
  184. // currTime:1654149186191,
  185. // deviceCode:"8b4eef5c5614033bfd3bcbdf4577c339",
  186. // iOS:{"idfa":"00000000-0000-0000-0000-000000000000"},
  187. // lang:"zh","model":"iPhone12,5","ov":"15.3.1",
  188. // pkgCate:"Main",
  189. // platform:"iOS",
  190. // resolution:{"h":2688,"s":3,"w":1242},
  191. // };
  192. // let token= uni.getStorageSync('token')||"88b99b11d3fc4cc3a71959b824678ce8";
  193. // uni.uploadFile({
  194. // url: `${apiHost}${url}`,
  195. // filePath: path,
  196. // name: 'file',
  197. // timeout: 10000,
  198. // header: {
  199. // 'token': token,
  200. // 'LL_Ukn': LL_Ukn,
  201. // 'LL_Csi': JSON.stringify(LL_Csi),
  202. // },
  203. // success: (res) => {
  204. // let result = JSON.parse(res.data);
  205. // if (result.status === 'Unauthorized') {
  206. // uni.reLaunch({
  207. // url:'/pages/login/login'
  208. // })
  209. // uni.showToast({
  210. // icon:'none',
  211. // title:'登录已失效'
  212. // })
  213. // }
  214. // else if(res.data.status === 'FrozenUser'){
  215. // // 用户异常
  216. // uni.reLaunch({
  217. // url:'/pages/login/login'
  218. // })
  219. // uni.showToast({
  220. // icon:'none',
  221. // title:"用户已被冻结"
  222. // })
  223. // }
  224. // else if(res.data.status=== 'Fail'){
  225. // // 用户异常
  226. // uni.reLaunch({
  227. // url:'/pages/login/login'
  228. // })
  229. // uni.showToast({
  230. // icon:'none',
  231. // title:res.data.msg
  232. // })
  233. // }
  234. // else if (result.status === 'Succ') {
  235. // resolve(result.data);
  236. // } else {
  237. // uni.showToast({
  238. // icon:'none',
  239. // title:result.msg
  240. // })
  241. // reject(result.data);
  242. // }
  243. // },
  244. // fail: (err) => {
  245. // reject(err.data);
  246. // }
  247. // })
  248. // })
  249. // }
  250. module.exports = {
  251. assetsUrl,
  252. request,
  253. get,
  254. showMsg,
  255. hasSafeArea,
  256. checkPhone,
  257. checkIdNo,
  258. checkChinese,
  259. compare,
  260. timeFn,
  261. protocal,
  262. IMSDKCode
  263. }