common.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. uni.setStorage({
  34. key: 'userinfo',
  35. data: info,
  36. success: function () {
  37. },
  38. fail:function(error){
  39. console.log('error');
  40. addlog({
  41. json: "用户信息保存失败",
  42. type: 'uniapp错误'
  43. })
  44. }
  45. });
  46. }
  47. /**
  48. * 清除缓存
  49. */
  50. export function clear(){
  51. try {
  52. uni.clearStorageSync();
  53. } catch (e) {
  54. showsysteinfo('error',"操作失败")
  55. addlog({
  56. json: "缓存清理失败",
  57. type: 'uniapp错误'
  58. })
  59. }
  60. }
  61. export function tostemlistnext(startindex,next=0,scaleid_1=false,srid_1=false){
  62. startindex = parseInt(startindex)+next
  63. let stemlist = uni.getStorageSync('stemlist')
  64. if(!stemlist){
  65. return false
  66. }
  67. let item = stemlist[startindex]
  68. //console.log(item)
  69. if(!item){
  70. return false
  71. }
  72. uni.setStorage({
  73. key: 'stemitem',
  74. data: item
  75. });
  76. if(item==undefined){
  77. return false
  78. }
  79. if(scaleid_1!==false&&srid_1!==false){
  80. if(item.stemtype<101){
  81. //标准答题
  82. uni.navigateTo({
  83. url: '/pages/topic/common'+"?scaleid="+scaleid_1 + "&srid=" + srid_1 + `&sindex=` + startindex
  84. });
  85. }else{
  86. //特殊答题
  87. let url = "/pages/topic/"+item.stemdefinepage+"?scaleid="+scaleid_1 + "&srid=" + srid_1 + `&sindex=` + startindex
  88. uni.navigateTo({
  89. url: url
  90. });
  91. }
  92. }else{
  93. let scaleid=4
  94. let srid = uni.getStorageSync('srid')
  95. if(item.stemtype<101){
  96. //标准答题
  97. uni.navigateTo({
  98. url: '/pages/topic/common'+"?scaleid="+scaleid + "&srid=" + srid + `&sindex=` + startindex
  99. });
  100. }else{
  101. //特殊答题
  102. let url = "/pages/topic/"+item.stemdefinepage+"?scaleid="+scaleid + "&srid=" + srid + `&sindex=` + startindex
  103. uni.navigateTo({
  104. url: url
  105. });
  106. }
  107. }
  108. return true
  109. }
  110. export function tohome(){
  111. uni.redirectTo({
  112. url: '/pages/index/index'
  113. });
  114. }