index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. // pages/index/index.js
  2. const app = getApp();
  3. const util = require('../../utils/util.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. imgPath: app.globalData.imgPath,
  10. path: app.globalData.path,
  11. username: app.globalData.userInfo.usernameShow,
  12. role_name: app.globalData.roleInfo.name,
  13. app_bottom: '大城细管·大城众管·大城智管',
  14. nextMeeting: null
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. let that = this;
  21. if (!app.globalData.userInfo.usernameShow || !app.globalData.userInfo.nickName || !app.globalData.userInfo.headImgUrl) {
  22. wx.showModal({
  23. title: '提示',
  24. content: '轻应用需要取您的用户信息',
  25. showCancel: false,
  26. confirmText: '确定',
  27. success: (res) => {
  28. if (res.confirm) {
  29. wx.getUserProfile({
  30. desc: '提升用户体验感',
  31. success: (res) => {
  32. app.globalData.userInfo.usernameShow = res.userInfo.nickName;
  33. app.globalData.userInfo.nickName = res.userInfo.nickName;
  34. app.globalData.userInfo.headImgUrl = res.userInfo.avatarUrl;
  35. that.setData({
  36. username: app.globalData.userInfo.usernameShow,
  37. role_name: app.globalData.roleInfo.name
  38. });
  39. util.post({
  40. url: '/sys/user/updateNoAuth',
  41. data: {
  42. id: app.globalData.userInfo.id,
  43. nickName: res.userInfo.nickName,
  44. usernameShow: res.userInfo.nickName,
  45. headImgUrl: res.userInfo.avatarUrl
  46. }
  47. });
  48. },
  49. fail: (res) => {
  50. util.toast('拒绝授权将影响您的体验感');
  51. that.setData({
  52. username: '未知用户',
  53. role_name: app.globalData.roleInfo.name
  54. });
  55. }
  56. });
  57. }
  58. },
  59. });
  60. } else {
  61. that.setData({
  62. username: app.globalData.userInfo.usernameShow,
  63. role_name: app.globalData.roleInfo.name
  64. });
  65. }
  66. // 下一场会议
  67. util.get({
  68. url: '/api/meeting/info/getNextMeeting',
  69. success: (res) => {
  70. wx.hideLoading();
  71. console.info(res)
  72. if (res.data.code != 200) {
  73. util.toast(res.data.msg);
  74. } else {
  75. let datas = res.data.data;
  76. if (datas) {
  77. that.setData({
  78. nextMeeting: datas,
  79. nextTitle: datas.title,
  80. nextTime: util.formatDate(datas.receptionTime),
  81. nextUnit: datas.receptionObject
  82. });
  83. } else {
  84. util.toast('暂无下一场会议');
  85. }
  86. }
  87. }
  88. });
  89. },
  90. /**
  91. * 生命周期函数--监听页面初次渲染完成
  92. */
  93. onReady: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面隐藏
  102. */
  103. onHide: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面卸载
  107. */
  108. onUnload: function () {
  109. },
  110. /**
  111. * 页面相关事件处理函数--监听用户下拉动作
  112. */
  113. onPullDownRefresh: function () {
  114. },
  115. /**
  116. * 页面上拉触底事件的处理函数
  117. */
  118. onReachBottom: function () {
  119. },
  120. /**
  121. * 用户点击右上角分享
  122. */
  123. onShareAppMessage: function () {
  124. },
  125. /**
  126. * 点击查看下一场会议详情
  127. */
  128. meetingInfo: function () {
  129. let nextMeeting = this.data.nextMeeting;
  130. if (nextMeeting) {
  131. wx.navigateTo({
  132. url: '../meeting-cover/meeting-cover?item=' + JSON.stringify(nextMeeting),
  133. });
  134. } else {
  135. util.toast('暂无下一场会议');
  136. }
  137. },
  138. /**
  139. * 日常巡检
  140. */
  141. dailyInspection: function () {
  142. wx.navigateTo({
  143. url: '../daily-inspection/daily-inspection',
  144. })
  145. },
  146. /**
  147. * 会议巡检
  148. */
  149. meetingInspection: function () {
  150. wx.navigateTo({
  151. url: '../meeting-list/meeting-list?type=INSPECTION',
  152. });
  153. },
  154. /**
  155. * 点击参观议程跳转至会议列表
  156. */
  157. visitAgenda: function () {
  158. wx.navigateTo({
  159. url: '../meeting-list/meeting-list',
  160. });
  161. },
  162. /**
  163. * 图片回传
  164. */
  165. uploadImage: function () {
  166. let that = this;
  167. wx.chooseImage({
  168. count: 1,
  169. success: function (res) {
  170. console.info(res.tempFilePaths);
  171. wx.uploadFile({
  172. filePath: res.tempFilePaths[0],
  173. name: 'file',
  174. url: that.data.path + '/api/upload/record/upload',
  175. header: {
  176. "Content-Type": "multipart/form-data",
  177. "Authorization": app.globalData.Authorization
  178. },
  179. formData: {
  180. fileType: 10
  181. },
  182. success(res) {
  183. console.info(res)
  184. }
  185. });
  186. }
  187. });
  188. },
  189. /**
  190. * 内容投屏
  191. */
  192. contentScreen: function () {
  193. let wifi, pass;
  194. // 打开微信扫一扫
  195. wx.scanCode({
  196. onlyFromCamera: true,
  197. scanType: 'qrCode',
  198. success: (res) => {
  199. console.info(res);
  200. if (res.result.indexOf('WIFI') < 0) {
  201. util.toast('请扫描WIFI二维码');
  202. return;
  203. }
  204. wx.showLoading({
  205. title: '加载中...',
  206. mask: true
  207. });
  208. try {
  209. let a = res.result.split(',');
  210. wifi = a[0].split(':')[1];
  211. pass = a[1].split(':')[1];
  212. } catch (error) {
  213. util.toast('请扫描WIFI二维码');
  214. return;
  215. }
  216. // 获取设备系统类型
  217. wx.getSystemInfo({
  218. success: (res) => {
  219. console.info(res);
  220. if (!res.wifiEnabled) {
  221. wx.hideLoading();
  222. util.toast('请打开WIFI功能');
  223. return;
  224. }
  225. // 1、初始化Wi-Fi模块
  226. wx.startWifi({
  227. success: (res) => {
  228. console.info(res)
  229. if (res.errMsg == 'startWifi:ok') {
  230. // 4、连接Wi-Fi
  231. wx.connectWifi({
  232. SSID: wifi,
  233. password: pass,
  234. success: (res) => {
  235. console.info(res);
  236. // 5、连接上Wi-Fi的事件回调
  237. wx.onWifiConnected((result) => {
  238. console.info(result);
  239. util.toast('WIFI连接成功', 'success');
  240. });
  241. // wx.getConnectedWifi({
  242. // success: (result) => {
  243. // wx.hideLoading();
  244. // console.info(result)
  245. // if (result.wifi.SSID === SSID) {
  246. // // 连接成功
  247. // } else {
  248. // // 连接失败
  249. // }
  250. // },
  251. // });
  252. },
  253. fail: (e) => {
  254. console.info(e);
  255. util.toast('WIFI连接失败');
  256. }
  257. });
  258. } else {
  259. util.toast(res.errMsg);
  260. }
  261. },
  262. fail: (e) => { }
  263. });
  264. },
  265. fail: (e) => {
  266. util.toast('获取设备系统类型失败');
  267. return;
  268. }
  269. });
  270. },
  271. fail: (e) => {
  272. util.toast('扫码失败,请重试');
  273. return;
  274. }
  275. });
  276. },
  277. changeRole: function () {
  278. wx.redirectTo({
  279. url: '../index-admin/index-admin',
  280. });
  281. },
  282. /**
  283. * 聊天室
  284. * @param {*} e
  285. */
  286. chatRoom: function (e) {
  287. wx.navigateTo({
  288. url: '../chat-room/chat-room',
  289. });
  290. },
  291. /**
  292. * 地图
  293. */
  294. lightMap: function () {
  295. wx.getSetting({
  296. withSubscriptions: true,
  297. success: function (res) {
  298. console.info(res);
  299. if (!res.authSetting['scope.userLocation']) {
  300. wx.authorize({
  301. scope: 'scope.userLocation',
  302. success: function (res) {
  303. console.info(res);
  304. wx.navigateTo({
  305. url: '../light-map/light-map',
  306. });
  307. },
  308. fail: function (e) {
  309. console.info(e);
  310. wx.showToast({
  311. title: '用户拒绝授权',
  312. icon: 'error'
  313. });
  314. }
  315. });
  316. } else {
  317. wx.navigateTo({
  318. url: '../light-map/light-map',
  319. });
  320. }
  321. }
  322. });
  323. }
  324. })