index.vue 9.8 KB

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