index.vue 19 KB

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