index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. <!-- <van-icon v-if="isCorpWX" class="kefu" name="service-o" size="30" color="#20a0ff" @click="tokefu" /> -->
  18. <div v-if="isCorpWX" class="kefu" @click="tokefu"><img src="../../assets/icon/kefu.png" alt=""></div>
  19. <div class="tip" v-if="!isCorpWX">
  20. 体验报表统计等更多功能,尽在PC端<br>
  21. 网页用户访问http://worktime.ttkuaiban.com,钉钉用户直接从钉钉PC端进入工时管家
  22. </div>
  23. <Footer ref="child" :key="key"></Footer>
  24. </div>
  25. </template>
  26. <script>
  27. import Footer from "@/components/Footer";
  28. export default {
  29. data() {
  30. return {
  31. isCorpWX:false,
  32. isWX:false,
  33. // user: JSON.parse(localStorage.userInfo) || '',
  34. user: '',
  35. unreadNum:0,
  36. images: [
  37. // require('../../assets/img/index/banner_1.png'),
  38. require('../../assets/img/index/banner4.jpeg'),
  39. // require('../../assets/img/index/banner_3.png'),
  40. ],
  41. routers: [],
  42. key: 0
  43. };
  44. },
  45. created() {
  46. if(localStorage.userInfo) {
  47. this.user = JSON.parse(localStorage.userInfo)
  48. }
  49. },
  50. mounted() {
  51. // 手机上看控制台
  52. // if(this.user.companyName == '比基尼小镇'){
  53. // let consoleScript = document.createElement("script");
  54. // consoleScript.src = "https://cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js";
  55. // consoleScript.onload = function () {
  56. // new VConsole()
  57. // }
  58. // document.head.appendChild(consoleScript);
  59. // }
  60. var ua = navigator.userAgent.toLowerCase();
  61. if (ua.indexOf("wxwork") > 0) {
  62. this.isCorpWX = true;
  63. } else if (ua.indexOf("micromessenger") > 0) {
  64. this.isWX = true;
  65. }
  66. let that = this
  67. if (localStorage.userInfo != null) {
  68. that.getAccountInfo();
  69. } else {
  70. if(window.location.href.indexOf('userId') != '-1') {
  71. that.getAccountInfo()
  72. } else {
  73. this.$router.push("/login");
  74. }
  75. }
  76. },
  77. components: {
  78. Footer
  79. },
  80. methods: {
  81. tokefu(){
  82. wx.invoke('openThirdAppServiceChat', {
  83. }, function(res) {
  84. console.log('invoke',res);
  85. if (res.err_msg == "openThirdAppServiceChat:ok" || res.err_msg == "openThirdAppServiceChat:cancel") {
  86. }else{
  87. this.$toast.fail('请联系管理员添加客服');
  88. }
  89. }
  90. );
  91. },
  92. // 模块
  93. getModule() {
  94. if(this.user.userNameNeedTranslate == '1'){
  95. this.agentConfig()
  96. }
  97. if (this.user.company.packageEngineering == 1) {
  98. this.routers.push(
  99. {
  100. name: '专业审核',
  101. url: '/profession_review',
  102. icon: 'todo-list-o'
  103. });
  104. }
  105. var list = this.user.moduleList
  106. for (var i in list) {
  107. if(list[i].name == '工时报告') {
  108. this.routers.push({name: '查看日报',url: '/calendar',icon: 'description'})
  109. this.routers.push({name: '填写日报',url: '/edit',icon: 'edit'})
  110. // if (this.user.companyId == 817 || this.user.companyId == 7 || this.user.companyId == 10) {
  111. this.routers.push({name: '按周填报',url: '/weekEdit',icon: 'records'})
  112. // }
  113. }
  114. if(list[i].name == '待办任务') {
  115. this.routers.push({
  116. name: '待办任务',
  117. url: '/task',
  118. icon: 'coupon-o'
  119. });
  120. }
  121. if(list[i].name == '项目报告审核') {
  122. this.routers.push({name: '项目报告审核',url: '/review',icon: 'todo-list-o'})
  123. }
  124. if(list[i].name == '项目管理') {
  125. this.routers.push({name: '项目管理',url: '/project',icon: 'label-o'})
  126. }
  127. if(list[i].name == '导入日报审核') {
  128. this.routers.push({name: '导入日报审核',url: '/audit',icon: 'completed'})
  129. }
  130. if(list[i].name == '费用报销') {
  131. this.routers.push({
  132. name: '费用报销',
  133. url: '/expense',
  134. icon: 'balance-list-o'
  135. });
  136. }
  137. }
  138. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  139. this.routers.push(
  140. {
  141. name: '部门审核',
  142. url: '/department_review',
  143. icon: 'todo-list-o'
  144. });
  145. }
  146. this.routers.push({
  147. name: '消息记录',
  148. url: '/msg',
  149. icon: 'todo-list-o',
  150. info: this.unreadNum
  151. });
  152. },
  153. // 获取企业微信参数
  154. agentConfig(){
  155. let curUrl = window.location.href.split('#')[0]
  156. this.$axios.post('/wxcorp/getCorpWXConfig',{
  157. url: curUrl,
  158. token: this.user.id
  159. }).then(res => {
  160. if(res.code == 'ok'){
  161. wx.config({
  162. beta: true,
  163. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  164. appId: res.data.appid, // 必填,公众号的唯一标识
  165. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  166. nonceStr: res.data.noncestr, // 必填,生成签名的随机串
  167. signature: res.data.sign, // 必填,签名,见附录1
  168. jsApiList: ['chooseImage','previewImage','uploadImage','downloadImage','previewFile','getLocation','agentConfig']
  169. })
  170. let that = this
  171. wx.ready(function(){
  172. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  173. that.$axios.post('/wxcorp/getCorpWXAgentConfig', {
  174. url: curUrl,
  175. token: that.user.id
  176. }).then(res => {
  177. if(res.code == 'ok'){
  178. wx.agentConfig({
  179. corpid: res.data.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
  180. agentid: res.data.agentid, // 必填,企业微信的应用id (e.g. 1000247)
  181. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  182. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  183. signature: res.data.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
  184. jsApiList: ['selectExternalContact','openThirdAppServiceChat'], //必填,传入需要使用的接口名称
  185. success: function (result) {
  186. // console.log(result, '请求微信成功')
  187. // console.log(window, 'window')
  188. // wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
  189. window.WWOpenData.bind(document.querySelector('ww-open-data'))
  190. // that.kefuShow = true
  191. },
  192. fail: function (res) {
  193. // console.log('查看错误信息', res)
  194. if (res.errMsg.indexOf('function not exist') > -1) {
  195. alert('版本过低请升级')
  196. }
  197. },
  198. })
  199. }
  200. }).catch(err => {
  201. if (err.errMsg.indexOf('function not exist') > -1) {
  202. alert('版本过低请升级')
  203. }
  204. })
  205. });
  206. }
  207. }).catch(err => {
  208. })
  209. },
  210. //获取账户信息
  211. getAccountInfo() {
  212. let userId = this.user.id
  213. if(window.location.href.indexOf('userId') != '-1') {
  214. let href = window.location.href;
  215. var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
  216. if (loginUserId.includes('#/')) {
  217. loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
  218. }
  219. userId = loginUserId
  220. }
  221. if(window.location.href.indexOf('errorMsg') != '-1') {
  222. this.$router.push("/login");
  223. }
  224. this.$axios.get('/user/loginByUserId', {params:{userId: userId}})
  225. .then(res => {
  226. // console.log(res);
  227. if (res.code == 'error') {
  228. localStorage.errorMsg = res.msg;
  229. //账号信息有问题,不能使用。
  230. this.$router.push("/error");
  231. } else {
  232. localStorage.userInfo = JSON.stringify(res.data);
  233. this.user = res.data;
  234. this.$refs.child.dealWith()
  235. this.key++
  236. this.getModule()
  237. this.getMessage();
  238. this.redirectIfNess();
  239. this.$forceUpdate()
  240. // this.bindIfNessary();
  241. }
  242. }).catch(err=> {
  243. alert('err=' + err);
  244. });
  245. },
  246. redirectIfNess() {
  247. var href = window.location.href;
  248. if (href.indexOf('path') > 0) {
  249. var path = href.split('path=')[1].split('&')[0];
  250. this.$router.push(path);
  251. }
  252. },
  253. bindIfNessary() {
  254. let href = window.location.href;
  255. var requestUrl = "";
  256. if (this.isCorpWX && (this.user.corpwxUserid == null|| this.user.corpwxUserid == undefined || this.user.corpwxUserid == 'undefined')) {//优先检查企业微信环境
  257. requestUrl = "/wxcorp/bindCorpWeiXin";
  258. } else if (this.isWX && (this.user.wxOpenid == null || this.user.wxOpenid == undefined || this.user.wxOpenid == 'undefined')) {
  259. requestUrl = "/wechat/bindWeiXin";
  260. }
  261. if (requestUrl.length > 0) {
  262. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  263. //会自动跳转到首页
  264. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  265. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  266. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  267. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  268. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  269. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  270. // console.log('urlRight=' + urlRight);
  271. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  272. //获取code
  273. var code = urlRight.substring('?code='.length,urlRight.indexOf('#/index'));
  274. if (code.indexOf('&state=1') > 0) {
  275. code = code.substring(0, code.indexOf('&state=1'));
  276. }
  277. //调用后台接口,注册用户
  278. // console.log('获取到code=='+code);
  279. this.$axios.get(requestUrl, {params:{code:code, userId: this.user.id}})
  280. .then(res => {
  281. // console.log(res);
  282. if (res == null) {
  283. this.$toast.fail('绑定失败');
  284. } else if(res.errcode != null) {
  285. //报错了
  286. console.log(res.errmsg);
  287. } else {
  288. //获取openId
  289. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  290. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  291. localStorage.userInfo = JSON.stringify(res.data);
  292. // console.log('绑定成功');
  293. this.user = res.data;
  294. window.location.href = '/#/my/center';
  295. }
  296. }
  297. }).catch(err=> {
  298. alert('err=' + err);
  299. });
  300. }
  301. }
  302. },
  303. //获取消息
  304. getMessage() {
  305. this.$axios.post("/information/list", {
  306. })
  307. .then(res => {
  308. if(res.code == "ok") {
  309. var list = res.data;
  310. this.unreadNum = list.filter(l=>l.checked==0).length;
  311. // console.log(this.unreadNum);
  312. }
  313. }).catch(err=> {this.$toast.clear();});
  314. },
  315. },
  316. activated(){
  317. this.getMessage()
  318. }
  319. };
  320. </script>
  321. <style lang="less" scoped>
  322. .swipe-img {
  323. img {
  324. width: 100%;
  325. height: 100%;
  326. }
  327. }
  328. .body {
  329. height: calc(100vh - 50px);
  330. position: relative;
  331. }
  332. .kefu{
  333. position: fixed;
  334. right: 35px;
  335. bottom: 120px;
  336. width: 36px;
  337. height: 36px;
  338. background-color: #fff;
  339. z-index: 1000;
  340. border-radius: 50%;
  341. img{
  342. margin: 4px;
  343. width: 28px;
  344. height: 28px;
  345. }
  346. }
  347. .tip {
  348. position: absolute;
  349. width: 100%;
  350. bottom: 5px;
  351. font-size: 14px;
  352. color: #8f8f8f;
  353. margin-top: 20px;
  354. text-align: center;
  355. line-height: 20px;
  356. }
  357. </style>