3
0

profile.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <div>
  3. <loading v-if="isLoading"
  4. :show="isLoading"
  5. text="正在加载"></loading>
  6. <div>
  7. <div class="p-base p-header">
  8. <img class="p-avatar"
  9. :src="imageURL">
  10. <span>{{user.Username}}</span>
  11. </div>
  12. <div class="p-base p-info">
  13. <table cellspacing="0">
  14. <tr>
  15. <td class="cell1">
  16. <span class="s1">名称</span>
  17. <span class="s2">{{user.Realname}}</span>
  18. </td>
  19. <td class="cell2">
  20. <span class="s1">手机</span>
  21. <span class="s2">{{user.Telephone}}</span>
  22. </td>
  23. </tr>
  24. <tr>
  25. <td class="cell3">
  26. <span class="s1">电话</span>
  27. <span class="s2">{{user.Mobile ? user.Mobile : '无'}}</span>
  28. </td>
  29. <td>
  30. <span class="s1">邮箱</span>
  31. <span class="s2">{{user.Email ? user.Email : '无'}}</span>
  32. </td>
  33. </tr>
  34. </table>
  35. </div>
  36. <box gap="20px 10px">
  37. <x-button type="primary"
  38. @click.native="generateaction">生成报警动作</x-button>
  39. <x-button type="warn"
  40. @click.native="logout">重新绑定</x-button>
  41. <!-- <x-button v-if="lockflag == 1"
  42. type="warn"
  43. @click.native="opendoor">开锁</x-button> -->
  44. </box>
  45. <actionsheet v-model="asShow"
  46. :menus="asMenu"
  47. @on-click-menu="doLogout"
  48. show-cancel
  49. cancel-text="取消"></actionsheet>
  50. <toast v-model="showInfo"
  51. :type="showtype"
  52. :time="2000">{{info}}</toast>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. import {
  58. XButton,
  59. Box,
  60. Actionsheet,
  61. Loading,
  62. Toast
  63. } from 'vux'
  64. import {
  65. mapGetters
  66. } from 'vuex'
  67. import store from 'store'
  68. import wx from 'weixin-jsapi'
  69. import Vue from 'vue'
  70. import axios from 'axios'
  71. Vue.prototype.wx = wx
  72. // import wx from "weixin-jsapi"
  73. export default {
  74. name: 'profile',
  75. components: {
  76. XButton,
  77. Box,
  78. Actionsheet,
  79. Loading,
  80. Toast
  81. },
  82. data () {
  83. return {
  84. isLoading: false,
  85. asShow: false,
  86. lockflag: 0,
  87. openid: '',
  88. user: {},
  89. username: '',
  90. imageURL: '',
  91. baseURL: 'http://1.117.158.212:8081',
  92. asMenu: {
  93. confirm: '去绑定账号'
  94. },
  95. currentPage: 1,
  96. size: 6,
  97. currentItemCount: 0,
  98. keyword: '',
  99. showInfo: false,
  100. info: '',
  101. showtype: ''
  102. }
  103. },
  104. computed: mapGetters({
  105. session: 'session'
  106. }),
  107. created () {
  108. this.openid = store.get('ygopenid')
  109. this.getuserinfo()
  110. // this.wxInitialization()
  111. // this.getChannels()
  112. },
  113. methods: {
  114. getChannels () {
  115. const params = { _currentPage: this.currentPage, _size: 100, keyword: this.keyword, openid: this.openid }
  116. this.$services.channel.get('list', { params })
  117. .then(res => {
  118. for (var i = 0; i < res.data.items.length; i++) {
  119. if (res.data.items[i].DataItem === 31) {
  120. this.lockflag = 1
  121. }
  122. }
  123. }).catch(() => { })
  124. },
  125. logout () {
  126. this.asShow = true;
  127. },
  128. wxInitialization () {
  129. // const params = { openid: 'wx.labsop.cn/ui/index.html#/profile' }
  130. const params = { openid: location.href.split('#')[0] }
  131. this.$services.channel.get('getwxconfig', { params })
  132. .then(res => {
  133. wx.config({
  134. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  135. appId: res.data.items.app_id, // 必填,公众号的唯一标识
  136. timestamp: res.data.items.timestamp, // 必填,生成签名的时间戳
  137. nonceStr: res.data.items.nonce_str, // 必填,生成签名的随机串
  138. signature: res.data.items.signature, // 必填,签名,见附录1
  139. jsApiList: [
  140. 'checkJsApi',
  141. 'startRecord',
  142. 'stopRecord',
  143. 'translateVoice',
  144. 'scanQRCode', // 微信扫一扫接口
  145. 'openCard'
  146. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  147. });
  148. wx.error(function (res) {
  149. alert('出错了:' + res.errMsg);// 这个地方的好处就是wx.config配置错误,会弹出窗口哪里错误,然后根据微信文档查询即可。
  150. });
  151. wx.ready(function () {
  152. wx.checkJsApi({
  153. jsApiList: ['scanQRCode'],
  154. success: function (res) {
  155. }
  156. });
  157. });
  158. })
  159. // this.$router.replace({ path: '/open' })
  160. // axios.request({
  161. // method: 'get',
  162. // url: 'http://39.98.34.197:12001/api/remote_control/rtuseedcmd?code=63000105&instruction=DO1=1'
  163. // }).then(resp => {
  164. // console.log('start --->', resp.data);
  165. // this.showInfo = true;
  166. // this.info = '开锁成功';
  167. // this.showtype = 'success';
  168. // }).catch(error => {
  169. // console.log(error);
  170. // });
  171. },
  172. opendoor () {
  173. wx.scanQRCode({
  174. needResult: 1, // 默认为0,扫描结果由微信处理,1 则直接返回扫描结果,
  175. scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  176. success: function (res) {
  177. // console.log('------res.resultStr----', res.resultStr)
  178. var result = res.resultStr;
  179. axios.request({
  180. method: 'get',
  181. url: 'http://iot.labsop.cn:12001/api/remote_control/rtuseedcmd?instruction=DO1=1&code=' + result + '&ygnick=' + store.get('ygnick') + '&ygopenid=' + store.get('ygopenid')
  182. }).then(resp => {
  183. // console.log('start -123-->', resp.data);
  184. if (resp.data.code !== 0) {
  185. alert('操作失败')
  186. } else {
  187. alert('操作成功')
  188. }
  189. // this.showInfo = true;
  190. // this.info = '开锁成功';
  191. // this.showtype = 'success';
  192. }).catch(error => {
  193. console.log(error);
  194. });
  195. },
  196. error: function (res) {
  197. alert(res, 2);
  198. if (res.errMsg.indexOf('function_not_exist') > 0) {
  199. alert('版本过低请升级')
  200. }
  201. }
  202. });
  203. },
  204. doLogout (key) {
  205. if (key === 'confirm') {
  206. this.$store.dispatch('deleteToken')
  207. this.$router.replace({ path: '/login' })
  208. }
  209. },
  210. getuserinfo () {
  211. const params = { openid: store.get('ygopenid') }
  212. this.$services.user.get('me', { params })
  213. .then(res => {
  214. this.user = res.data.Profile;
  215. this.imageURL = this.baseURL + this.user.Photo;
  216. if (this.user.Photo === '') {
  217. this.imageURL = this.imageURL + '/static/equipmentimg/avatar-default.jpg'
  218. }
  219. }).catch(() => {
  220. })
  221. },
  222. generateaction () {
  223. let _this = this
  224. let params = { openid: store.get('ygopenid'), nick: store.get('ygnick') }
  225. return _this.$services.channel.put('generateaction', params)
  226. .then(res => {
  227. if (res.data.code === 0) {
  228. this.showInfo = true;
  229. this.info = res.data.message;
  230. this.showtype = 'success';
  231. } else {
  232. this.showInfo = true;
  233. this.info = res.data.message;
  234. this.showtype = 'cancel';
  235. }
  236. })
  237. }
  238. }
  239. }
  240. </script>
  241. <style>
  242. html,
  243. body {
  244. background-color: #eeeeee;
  245. color: #424242;
  246. -webkit-touch-callout: none;
  247. -webkit-user-select: none;
  248. }
  249. .p-base {
  250. border-top: 1px solid #e0e0e0;
  251. border-bottom: 1px solid #e0e0e0;
  252. background-color: white;
  253. margin-top: 20px;
  254. }
  255. .p-info {
  256. display: block;
  257. width: 100%;
  258. }
  259. .p-info table {
  260. width: 100%;
  261. }
  262. .p-info table td {
  263. padding: 10px;
  264. width: 50%;
  265. }
  266. .cell1 {
  267. border-bottom: 1px solid #eeeeee;
  268. border-right: 1px solid #eeeeee;
  269. }
  270. .cell2 {
  271. border-bottom: 1px solid #eeeeee;
  272. }
  273. .cell3 {
  274. border-right: 1px solid #eeeeee;
  275. }
  276. .s1 {
  277. display: block;
  278. color: #9e9e9e;
  279. font-size: 14px;
  280. }
  281. .s2 {
  282. display: block;
  283. }
  284. .p-header {
  285. text-align: center;
  286. padding: 20px;
  287. }
  288. .p-header span {
  289. display: block;
  290. font-size: 20px;
  291. }
  292. .p-avatar {
  293. width: 100px;
  294. height: 100px;
  295. }
  296. </style>