index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. androidMarket:'WechatMP',
  105. model:deviceConfig.model,
  106. heartBeatParam:{
  107. city:encodeURIComponent(uni.getStorageSync('city')),
  108. geo:{
  109. lat:String(uni.getStorageSync('latitude')),
  110. lon:String(uni.getStorageSync('longitude'))
  111. }
  112. }
  113. };
  114. let token= uni.getStorageSync('token');
  115. uni.request({
  116. url: `${apiHost}${url}`,
  117. method: method,
  118. data: data,
  119. header: {
  120. 'Content-Type': 'application/json',
  121. // 'token': url === ('/cufd') ? '' : token,
  122. // 'LL_Ukn': url === ('/cufd') ? '' : LL_Ukn,
  123. // 'LL_Csi':url === ('/cufd') ? '' : JSON.stringify(LL_Csi),
  124. 'token': url === 'userLogin/login' ? '' : token,
  125. 'LL_Ukn': LL_Ukn,
  126. 'LL_Csi': JSON.stringify(LL_Csi),
  127. },
  128. success: res => {
  129. if (res.data.status === 'Unauthorized') {
  130. uni.$TUIKit.logout();
  131. uni.$TUIKit.destroy();
  132. uni.setStorageSync('token','');
  133. uni.setStorageSync('LL_Ukn','');
  134. uni.setStorageSync('userInfo','');
  135. uni.setStorageSync('user','');
  136. uni.setStorageSync('isLogin','no');
  137. reject();
  138. }
  139. else if(res.data.status === 'FrozenUser'){
  140. // 用户异常
  141. uni.showToast({
  142. icon:'none',
  143. title:"用户已被冻结"
  144. })
  145. }
  146. else if(res.data.status=== 'Fail'){
  147. // 用户异常
  148. uni.showToast({
  149. icon:'none',
  150. title:res.data.msg
  151. })
  152. }
  153. else if(res.data.status=== 'Exception'){
  154. // 自动登录异常
  155. uni.showToast({
  156. icon:'none',
  157. title:res.data.msg
  158. })
  159. }
  160. else if(res.data.status==='Succ'||res.data.code===0){
  161. resolve(res.data)
  162. }
  163. else{
  164. uni.showToast({
  165. icon:'none',
  166. title:res.data.msg
  167. })
  168. reject(res.data)
  169. }
  170. },
  171. fail: res => {
  172. console.log(res);
  173. reject(res.data)
  174. },
  175. complete: res => {}
  176. });
  177. });
  178. }
  179. const get = (url) => {
  180. return new Promise((resolve,reject)=>{
  181. uni.request({
  182. url:url,
  183. method:'GET',
  184. header:{'Access-Control-Allow-Origin':'*'},
  185. success:res=>{
  186. return res.data
  187. }
  188. })
  189. })
  190. }
  191. // const upload = (url, path) => {
  192. // return new Promise((resolve, reject) => {
  193. // let LL_Ukn =uni.getStorageSync('LL_Ukn')||"szxe/TwE/wNJxcF+51069Dw3KHJQmbEuE2tEVHG4ETQ1TEnZ6loF7MQdmCFePTWTS9NE8zhDBrvPplTUYNnlPa10jJ1GycLQjpe2CkO+UvflA8adpe/uD5z2C8Bp1Pg9cThzHmqxeAe1Oq9G1eo3PKfGGYLALGx+dgFPYMn06M/Y+lVio4WpXbNW8KMNkWyxnFZnpZEXzzyDUCT13TMF9tevVJ9/Sb3yBgLiLYnydplax+zjkFqwGSiDrQWR/E8s";
  194. // let LL_Csi=uni.getStorageSync('LL_Csi')||{
  195. // av:"2.6.0",
  196. // brand:"Apple",
  197. // currTime:1654149186191,
  198. // deviceCode:"8b4eef5c5614033bfd3bcbdf4577c339",
  199. // iOS:{"idfa":"00000000-0000-0000-0000-000000000000"},
  200. // lang:"zh","model":"iPhone12,5","ov":"15.3.1",
  201. // pkgCate:"Main",
  202. // platform:"iOS",
  203. // resolution:{"h":2688,"s":3,"w":1242},
  204. // };
  205. // let token= uni.getStorageSync('token')||"88b99b11d3fc4cc3a71959b824678ce8";
  206. // uni.uploadFile({
  207. // url: `${apiHost}${url}`,
  208. // filePath: path,
  209. // name: 'file',
  210. // timeout: 10000,
  211. // header: {
  212. // 'token': token,
  213. // 'LL_Ukn': LL_Ukn,
  214. // 'LL_Csi': JSON.stringify(LL_Csi),
  215. // },
  216. // success: (res) => {
  217. // let result = JSON.parse(res.data);
  218. // if (result.status === 'Unauthorized') {
  219. // uni.reLaunch({
  220. // url:'/pages/login/login'
  221. // })
  222. // uni.showToast({
  223. // icon:'none',
  224. // title:'登录已失效'
  225. // })
  226. // }
  227. // else if(res.data.status === 'FrozenUser'){
  228. // // 用户异常
  229. // uni.reLaunch({
  230. // url:'/pages/login/login'
  231. // })
  232. // uni.showToast({
  233. // icon:'none',
  234. // title:"用户已被冻结"
  235. // })
  236. // }
  237. // else if(res.data.status=== 'Fail'){
  238. // // 用户异常
  239. // uni.reLaunch({
  240. // url:'/pages/login/login'
  241. // })
  242. // uni.showToast({
  243. // icon:'none',
  244. // title:res.data.msg
  245. // })
  246. // }
  247. // else if (result.status === 'Succ') {
  248. // resolve(result.data);
  249. // } else {
  250. // uni.showToast({
  251. // icon:'none',
  252. // title:result.msg
  253. // })
  254. // reject(result.data);
  255. // }
  256. // },
  257. // fail: (err) => {
  258. // reject(err.data);
  259. // }
  260. // })
  261. // })
  262. // }
  263. module.exports = {
  264. assetsUrl,
  265. request,
  266. get,
  267. showMsg,
  268. hasSafeArea,
  269. checkPhone,
  270. checkIdNo,
  271. checkChinese,
  272. compare,
  273. timeFn,
  274. protocal,
  275. IMSDKCode
  276. }