index.js 7.9 KB

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