index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <div class="body">
  3. <van-swipe class="my-swipe" :autoplay="3000" :height="200" indicator-color="white">
  4. <van-swipe-item v-for="(item, index) in images" :key="index" class="swipe-img">
  5. <img :src="item"/>
  6. </van-swipe-item>
  7. </van-swipe>
  8. <van-grid :column-num="3">
  9. <van-grid-item v-for="(item,index) in routers" :key="index" :icon="item.icon" :text="item.name"
  10. :info="item.name=='消息记录'&&unreadNum>0?unreadNum:''"
  11. :to="item.url">
  12. </van-grid-item>
  13. </van-grid>
  14. <div class="tip">
  15. 体验报表统计等更多功能,尽在PC端<br>
  16. 网页用户访问http://worktime.ttkuaiban.com,钉钉用户直接从钉钉PC端进入工时管家
  17. </div>
  18. <Footer page="index"></Footer>
  19. </div>
  20. </template>
  21. <script>
  22. import Footer from "@/components/Footer";
  23. export default {
  24. data() {
  25. return {
  26. isCorpWX:false,
  27. isWX:false,
  28. user: JSON.parse(localStorage.userInfo),
  29. unreadNum:0,
  30. images: [
  31. // require('../../assets/img/index/banner_1.png'),
  32. require('../../assets/img/index/banner4.jpeg'),
  33. // require('../../assets/img/index/banner_3.png'),
  34. ],
  35. routers: [
  36. {
  37. name: '我的日报',
  38. url: '/calendar',
  39. icon: 'description'
  40. },
  41. {
  42. name: '填写日报',
  43. url: '/edit',
  44. icon: 'edit'
  45. },
  46. ],
  47. };
  48. },
  49. created() {
  50. let index = this.active + 1;
  51. this.list = this[`list${index}`]; // this.list1
  52. },
  53. mounted() {
  54. var ua = navigator.userAgent.toLowerCase();
  55. if (ua.indexOf("wxwork") > 0) {
  56. this.isCorpWX = true;
  57. } else if (ua.indexOf("micromessenger") > 0) {
  58. this.isWX = true;
  59. }
  60. if (this.user.company.packageEngineering == 1) {
  61. this.routers.push(
  62. {
  63. name: '专业审核',
  64. url: '/profession_review',
  65. icon: 'todo-list-o'
  66. });
  67. }
  68. if (this.user.role == 0) {
  69. //普通员工
  70. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  71. this.routers.push(
  72. {
  73. name: '部门审核',
  74. url: '/department_review',
  75. icon: 'todo-list-o'
  76. });
  77. }
  78. if (this.user.leader) {
  79. this.routers.push({
  80. name: '项目报告审核',
  81. url: '/review',
  82. icon: 'todo-list-o'
  83. });
  84. }
  85. } else if (this.user.role == 1 || this.user.role == 2){
  86. if (this.user.company.packageEngineering == 1) {
  87. this.routers.push(
  88. {
  89. name: '部门审核',
  90. url: '/department_review',
  91. icon: 'todo-list-o'
  92. });
  93. }
  94. this.routers.push({
  95. name: '项目报告审核',
  96. url: '/review',
  97. icon: 'todo-list-o'
  98. });
  99. this.routers.push({
  100. name: '项目管理',
  101. url: '/project',
  102. icon: 'label-o'
  103. });
  104. } else {
  105. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  106. this.routers.push(
  107. {
  108. name: '部门审核',
  109. url: '/department_review',
  110. icon: 'todo-list-o'
  111. });
  112. }
  113. if (this.user.role == 5) {//项目管理员
  114. this.routers.push({
  115. name: '项目管理',
  116. url: '/project',
  117. icon: 'label-o'
  118. });
  119. }
  120. }
  121. this.routers.push({
  122. name: '消息记录',
  123. url: '/msg',
  124. icon: 'todo-list-o',
  125. info: this.unreadNum
  126. });
  127. this.getMessage();
  128. this.bindIfNessary();
  129. },
  130. components: {
  131. Footer
  132. },
  133. methods: {
  134. bindIfNessary() {
  135. let href = window.location.href;
  136. var requestUrl = "";
  137. if (this.isCorpWX && (this.user.corpwxUserid != null|| this.user.corpwxUserid == undefined || this.user.corpwxUserid == 'undefined')) {//优先检查企业微信环境
  138. requestUrl = "/wxcorp/bindCorpWeiXin";
  139. } else if (this.isWX && (this.user.wxOpenid == null || this.user.wxOpenid == undefined || this.user.wxOpenid == 'undefined')) {
  140. requestUrl = "/wechat/bindWeiXin";
  141. }
  142. if (requestUrl.length > 0) {
  143. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  144. //会自动跳转到首页
  145. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  146. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  147. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  148. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  149. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  150. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  151. console.log('urlRight=' + urlRight);
  152. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  153. //获取code
  154. var code = urlRight.substring('?code='.length,urlRight.indexOf('#/index'));
  155. if (code.indexOf('&state=1') > 0) {
  156. code = code.substring(0, code.indexOf('&state=1'));
  157. }
  158. //调用后台接口,注册用户
  159. console.log('获取到code=='+code);
  160. this.$axios.get(requestUrl, {params:{code:code, userId: this.user.id}})
  161. .then(res => {
  162. console.log(res);
  163. if (res == null) {
  164. this.$toast.fail('绑定失败');
  165. } else if(res.errcode != null) {
  166. //报错了
  167. console.log(res.errmsg);
  168. } else {
  169. //获取openId
  170. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  171. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  172. localStorage.userInfo = JSON.stringify(res.data);
  173. console.log('绑定成功');
  174. this.user = res.data;
  175. window.location.href = '/#/my/center';
  176. }
  177. }
  178. }).catch(err=> {
  179. alert('err=' + err);
  180. });
  181. }
  182. }
  183. },
  184. getGoods() {
  185. let url = "/goods"; // /api/goods
  186. this.$axios
  187. .get(url)
  188. .then(res => {
  189. console.log("res", res);
  190. })
  191. .catch(err => {
  192. console.log("err", err);
  193. });
  194. },
  195. //获取消息
  196. getMessage() {
  197. this.$axios.post("/information/list", {
  198. })
  199. .then(res => {
  200. if(res.code == "ok") {
  201. var list = res.data;
  202. this.unreadNum = list.filter(l=>l.checked==0).length;
  203. console.log(this.unreadNum);
  204. }
  205. }).catch(err=> {toast.clear();});
  206. },
  207. }
  208. };
  209. </script>
  210. <style lang="less" scoped>
  211. .swipe-img {
  212. img {
  213. width: 100%;
  214. height: 100%;
  215. }
  216. }
  217. .body {
  218. height: calc(100vh - 50px);
  219. position: relative;
  220. }
  221. .tip {
  222. position: absolute;
  223. width: 100%;
  224. bottom: 5px;
  225. font-size: 14px;
  226. color: #8f8f8f;
  227. margin-top: 20px;
  228. text-align: center;
  229. line-height: 20px;
  230. }
  231. </style>