common.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {addlog} from "@/common/api/system.js"
  2. /**
  3. * @param {Object} type error info success
  4. * @param {Object} message
  5. */
  6. export function showsysteinfo(type,message){
  7. let icon =success
  8. switch(type){
  9. case "error":
  10. icon="success";
  11. break;
  12. case "info":
  13. icon="none";
  14. break;
  15. case "success":
  16. icon="success";
  17. break;
  18. }
  19. uni.showToast({
  20. title: message,
  21. icon:icon,
  22. duration: 2000
  23. });
  24. }
  25. export function islogin(){
  26. let userinfo = uni.getStorageSync("userinfo");
  27. if(!userinfo){
  28. return false;
  29. }
  30. return true
  31. }
  32. export function saveuserinfo(info){
  33. console.log(info)
  34. uni.setStorage({
  35. key: 'userinfo',
  36. data: info,
  37. success: function () {
  38. },
  39. fail:function(error){
  40. console.log('error');
  41. addlog({
  42. json: "用户信息保存失败",
  43. type: 'uniapp错误'
  44. })
  45. }
  46. });
  47. }
  48. /**
  49. * 清除缓存
  50. */
  51. export function clear(){
  52. try {
  53. uni.clearStorageSync();
  54. } catch (e) {
  55. showsysteinfo('error',"操作失败")
  56. addlog({
  57. json: "缓存清理失败",
  58. type: 'uniapp错误'
  59. })
  60. }
  61. }
  62. export function tostemlistnext(startindex,next=0,scaleid_1=false,srid_1=false){
  63. startindex = parseInt(startindex)+next
  64. let stemlist = uni.getStorageSync('stemlist')
  65. if(!stemlist){
  66. return false
  67. }
  68. let item = stemlist[startindex]
  69. //console.log(item)
  70. if(!item){
  71. return false
  72. }
  73. uni.setStorage({
  74. key: 'stemitem',
  75. data: item
  76. });
  77. if(item==undefined){
  78. return false
  79. }
  80. if(scaleid_1!==false&&srid_1!==false){
  81. if(item.stemtype<101){
  82. //标准答题
  83. uni.navigateTo({
  84. url: '/pages/topic/common'+"?scaleid="+scaleid_1 + "&srid=" + srid_1 + `&sindex=` + startindex
  85. });
  86. }else{
  87. //特殊答题
  88. let url = "/pages/topic/"+item.stemdefinepage+"?scaleid="+scaleid_1 + "&srid=" + srid_1 + `&sindex=` + startindex
  89. uni.navigateTo({
  90. url: url
  91. });
  92. }
  93. }else{
  94. let scaleid=4
  95. let srid = uni.getStorageSync('srid')
  96. if(item.stemtype<101){
  97. //标准答题
  98. uni.navigateTo({
  99. url: '/pages/topic/common'+"?scaleid="+scaleid + "&srid=" + srid + `&sindex=` + startindex
  100. });
  101. }else{
  102. //特殊答题
  103. let url = "/pages/topic/"+item.stemdefinepage+"?scaleid="+scaleid + "&srid=" + srid + `&sindex=` + startindex
  104. uni.navigateTo({
  105. url: url
  106. });
  107. }
  108. }
  109. return true
  110. }
  111. export function tohome(){
  112. // uni.redirectTo({
  113. // url: '/pages/index/index'
  114. // });
  115. uni.switchTab({
  116. url: '/pages/index/index'
  117. });
  118. }