index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. name: '查看日报',
  41. url: '/calendar',
  42. icon: 'description'
  43. },
  44. {
  45. name: '填写日报',
  46. url: '/edit',
  47. icon: 'edit'
  48. },
  49. ],
  50. };
  51. },
  52. created() {
  53. let index = this.active + 1;
  54. this.list = this[`list${index}`]; // this.list1
  55. },
  56. mounted() {
  57. var ua = navigator.userAgent.toLowerCase();
  58. if (ua.indexOf("wxwork") > 0) {
  59. this.isCorpWX = true;
  60. } else if (ua.indexOf("micromessenger") > 0) {
  61. this.isWX = true;
  62. }
  63. if (this.user.company.packageEngineering == 1) {
  64. this.routers.push(
  65. {
  66. name: '专业审核',
  67. url: '/profession_review',
  68. icon: 'todo-list-o'
  69. });
  70. }
  71. if (this.user.role == 0) {
  72. //普通员工
  73. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  74. this.routers.push(
  75. {
  76. name: '部门审核',
  77. url: '/department_review',
  78. icon: 'todo-list-o'
  79. });
  80. }
  81. if (this.user.leader) {
  82. this.routers.push({
  83. name: '项目报告审核',
  84. url: '/review',
  85. icon: 'todo-list-o'
  86. });
  87. }
  88. } else if (this.user.role == 1 || this.user.role == 2 || this.user.role == 5){
  89. // } else if (this.user.role == 1 || this.user.role == 2){
  90. if (this.user.company.packageEngineering == 1) {
  91. this.routers.push(
  92. {
  93. name: '部门审核',
  94. url: '/department_review',
  95. icon: 'todo-list-o'
  96. });
  97. }
  98. this.routers.push({
  99. name: '项目报告审核',
  100. url: '/review',
  101. icon: 'todo-list-o'
  102. });
  103. this.routers.push({
  104. name: '项目管理',
  105. url: '/project',
  106. icon: 'label-o'
  107. });
  108. // 自己加的
  109. // this.routers.push({
  110. // name: '导入日报审核',
  111. // url: '/audit',
  112. // icon: 'label-o'
  113. // });
  114. } else {
  115. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  116. this.routers.push(
  117. {
  118. name: '部门审核',
  119. url: '/department_review',
  120. icon: 'todo-list-o'
  121. });
  122. }
  123. if (this.user.role == 3||this.user.role == 5||this.user.role == 6) {//项目管理员,公司领导,公司高层
  124. this.routers.push({
  125. name: '项目管理',
  126. url: '/project',
  127. icon: 'label-o'
  128. });
  129. }
  130. if (this.user.leader) {
  131. this.routers.push({
  132. name: '项目报告审核',
  133. url: '/review',
  134. icon: 'todo-list-o'
  135. });
  136. }
  137. }
  138. if(this.user.role == 1 || this.user.role == 2) {
  139. this.routers.push({
  140. name: '导入日报审核',
  141. url: '/audit',
  142. icon: 'label-o'
  143. });
  144. } else {
  145. if(this.user.role == 6 && this.user.timeType.needDeptAudit == 1) {
  146. this.routers.push({
  147. name: '导入日报审核',
  148. url: '/audit',
  149. icon: 'label-o'
  150. });
  151. }
  152. }
  153. this.routers.push({
  154. name: '消息记录',
  155. url: '/msg',
  156. icon: 'todo-list-o',
  157. info: this.unreadNum
  158. });
  159. this.getMessage();
  160. this.bindIfNessary();
  161. if (localStorage.userInfo != null) {
  162. this.getAccountInfo();
  163. }
  164. this.routers.push({
  165. name: '自动计时',
  166. url: '/timetool',
  167. icon: 'clock-o',
  168. info: this.unreadNum
  169. });
  170. this.getMessage();
  171. this.bindIfNessary();
  172. if (localStorage.userInfo != null) {
  173. this.getAccountInfo();
  174. }
  175. },
  176. components: {
  177. Footer
  178. },
  179. methods: {
  180. //获取账户信息
  181. getAccountInfo() {
  182. this.$axios.get('/user/loginByUserId', {params:{userId: this.user.id}})
  183. .then(res => {
  184. console.log(res);
  185. if (res.code == 'error') {
  186. localStorage.errorMsg = res.msg;
  187. //账号信息有问题,不能使用。
  188. this.$router.push("/error");
  189. } else {
  190. localStorage.userInfo = JSON.stringify(res.data);
  191. this.user = res.data;
  192. }
  193. }).catch(err=> {
  194. alert('err=' + err);
  195. });
  196. },
  197. bindIfNessary() {
  198. let href = window.location.href;
  199. var requestUrl = "";
  200. if (this.isCorpWX && (this.user.corpwxUserid == null|| this.user.corpwxUserid == undefined || this.user.corpwxUserid == 'undefined')) {//优先检查企业微信环境
  201. requestUrl = "/wxcorp/bindCorpWeiXin";
  202. } else if (this.isWX && (this.user.wxOpenid == null || this.user.wxOpenid == undefined || this.user.wxOpenid == 'undefined')) {
  203. requestUrl = "/wechat/bindWeiXin";
  204. }
  205. if (requestUrl.length > 0) {
  206. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  207. //会自动跳转到首页
  208. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  209. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  210. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  211. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  212. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  213. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  214. console.log('urlRight=' + urlRight);
  215. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  216. //获取code
  217. var code = urlRight.substring('?code='.length,urlRight.indexOf('#/index'));
  218. if (code.indexOf('&state=1') > 0) {
  219. code = code.substring(0, code.indexOf('&state=1'));
  220. }
  221. //调用后台接口,注册用户
  222. console.log('获取到code=='+code);
  223. this.$axios.get(requestUrl, {params:{code:code, userId: this.user.id}})
  224. .then(res => {
  225. console.log(res);
  226. if (res == null) {
  227. this.$toast.fail('绑定失败');
  228. } else if(res.errcode != null) {
  229. //报错了
  230. console.log(res.errmsg);
  231. } else {
  232. //获取openId
  233. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  234. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  235. localStorage.userInfo = JSON.stringify(res.data);
  236. console.log('绑定成功');
  237. this.user = res.data;
  238. window.location.href = '/#/my/center';
  239. }
  240. }
  241. }).catch(err=> {
  242. alert('err=' + err);
  243. });
  244. }
  245. }
  246. },
  247. getGoods() {
  248. let url = "/goods"; // /api/goods
  249. this.$axios
  250. .get(url)
  251. .then(res => {
  252. console.log("res", res);
  253. })
  254. .catch(err => {
  255. console.log("err", err);
  256. });
  257. },
  258. //获取消息
  259. getMessage() {
  260. this.$axios.post("/information/list", {
  261. })
  262. .then(res => {
  263. if(res.code == "ok") {
  264. var list = res.data;
  265. this.unreadNum = list.filter(l=>l.checked==0).length;
  266. console.log(this.unreadNum);
  267. }
  268. }).catch(err=> {toast.clear();});
  269. },
  270. },
  271. activated(){
  272. this.getMessage()
  273. }
  274. };
  275. </script>
  276. <style lang="less" scoped>
  277. .swipe-img {
  278. img {
  279. width: 100%;
  280. height: 100%;
  281. }
  282. }
  283. .body {
  284. height: calc(100vh - 50px);
  285. position: relative;
  286. }
  287. .tip {
  288. position: absolute;
  289. width: 100%;
  290. bottom: 5px;
  291. font-size: 14px;
  292. color: #8f8f8f;
  293. margin-top: 20px;
  294. text-align: center;
  295. line-height: 20px;
  296. }
  297. </style>