work-web.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // pages/progress/work-web.js
  2. const api = require('../../utils/o2Api.js');
  3. const util = require('../../utils/util.js');
  4. Page({
  5. /**
  6. * Page initial data
  7. */
  8. data: {
  9. workUrl:'',
  10. navTitle: ''
  11. },
  12. /**
  13. * Lifecycle function--Called when page load
  14. */
  15. onLoad: function (options) {
  16. var title = decodeURIComponent(options.title);
  17. if(!options.workCompleted && !options.work && !options.draft) {
  18. util.toast('参数错误!');
  19. wx.navigateBack({
  20. delta: 1,
  21. });
  22. } else if(options.workCompleted) {
  23. this.openWorkCompletedUrl(options.workCompleted, title);
  24. } else if(options.work) {
  25. this.openWorkUrl(options.work, title);
  26. } else if(options.draft) {
  27. this.openDraft(options.draft, title);
  28. }
  29. },
  30. // 生成url
  31. _urlWithToken: function(url) {
  32. let newUrl = url;
  33. const who = wx.getStorageSync('who');
  34. const tokenName = wx.getStorageSync('tokenName');
  35. let token = ''
  36. if (who && who.token) {
  37. token = who.token;
  38. newUrl = newUrl + '&'+tokenName+'=' + token;
  39. }
  40. return newUrl + '#wechat_redirect';
  41. },
  42. // 打开工作表单 草稿
  43. openDraft: function(draft, title = '') {
  44. let url = api.workDraftUrl(draft);
  45. url = this._urlWithToken(url);
  46. this.setData({
  47. workUrl: url,
  48. navTitle: title
  49. });
  50. },
  51. // 打开工作表单 未完成的工作
  52. openWorkUrl: function(work, title = '') {
  53. let url = api.workWebUrl(work);
  54. url = this._urlWithToken(url);
  55. this.setData({
  56. workUrl: url,
  57. navTitle: title
  58. });
  59. },
  60. // 打开工作表单 已结束的工作
  61. openWorkCompletedUrl: function(workcompletedid, title = '') {
  62. let url = api.workCompletedWebUrl(workcompletedid);
  63. url = this._urlWithToken(url);
  64. this.setData({
  65. workUrl: url,
  66. navTitle: title
  67. });
  68. },
  69. /**
  70. * Lifecycle function--Called when page is initially rendered
  71. */
  72. onReady: function () {
  73. },
  74. /**
  75. * Lifecycle function--Called when page show
  76. */
  77. onShow: function () {
  78. },
  79. /**
  80. * Lifecycle function--Called when page hide
  81. */
  82. onHide: function () {
  83. },
  84. /**
  85. * Lifecycle function--Called when page unload
  86. */
  87. onUnload: function () {
  88. },
  89. /**
  90. * Page event handler function--Called when user drop down
  91. */
  92. onPullDownRefresh: function () {
  93. },
  94. /**
  95. * Called when page reach bottom
  96. */
  97. onReachBottom: function () {
  98. },
  99. /**
  100. * Called when user click on the top right corner to share
  101. */
  102. onShareAppMessage: function () {
  103. }
  104. })