menu.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <view class="mine-area">
  3. <image style="width: 100%;" mode="aspectFill" :src="imgSrc('/profile/logo/menuBackgroundImage.png')"></image>
  4. <view class="big-circle"></view>
  5. <view class="avatar-area z10" >
  6. <view class="img-boxs" @click="handleUpImg">
  7. <image :src="imgSrc(avatar)"></image>
  8. <cover-view>修改头像</cover-view>
  9. </view>
  10. <!-- <u-avatar :src="avatar.length > 0 ? imgSrc(avatar) : src" size="80" shape="circle"></u-avatar> -->
  11. </view>
  12. <view class="menu-area z10">
  13. <view class="basic-msg">
  14. <text class="basic-name">{{name}}</text>
  15. <!-- <text class="basic-amount">借用中设备:{{amount}}</text> -->
  16. </view>
  17. <u-list
  18. :enableFlex="true"
  19. >
  20. <u-list-item>
  21. <view class="menu-list" @click="toPersonInfo">
  22. <i class="iconfont icon-ditu"></i>
  23. <text>我的信息</text>
  24. </view>
  25. </u-list-item>
  26. <u-list-item>
  27. <view class="menu-list" @click="toBorrowRecord">
  28. <i class="iconfont icon-qianbao"></i>
  29. <text style="margin-right: 10rpx;">借用记录</text>
  30. <u-badge max="99" :value="amount"></u-badge>
  31. </view>
  32. </u-list-item>
  33. <u-list-item>
  34. <view class="menu-list" @click="toRepeat">
  35. <i class="iconfont icon-a-shezhi2"></i>
  36. <text>故障上报</text>
  37. </view>
  38. </u-list-item>
  39. <u-list-item v-if="role==='admin'?true:false">
  40. <view class="menu-list" @click="toHandleFault">
  41. <i class="iconfont icon-baogaoguanli"></i>
  42. <text>故障处理</text>
  43. </view>
  44. </u-list-item>
  45. <u-list-item v-if="role==='admin'?true:false">
  46. <view class="menu-list" @click="showPopup">
  47. <i class="iconfont icon-bangzhu"></i>
  48. <text>重置密码</text>
  49. </view>
  50. </u-list-item>
  51. <!--
  52. <u-list-item>
  53. <view class="menu-list">
  54. <i class="iconfont "></i>
  55. <text>关于我们</text>
  56. </view>
  57. </u-list-item> -->
  58. <u-list-item>
  59. <view class="menu-list" @click="toLogout">
  60. <i class="iconfont icon-tuichu"></i>
  61. <text>退出登录</text>
  62. </view>
  63. </u-list-item>
  64. </u-list>
  65. </view>
  66. <u-popup :show="show" @close="close" :round="10" closeable>
  67. <view class="popup-area">
  68. <view class="form-area" style="padding:0 20rpx;">
  69. <text class="form-label">工号</text>
  70. <u--input placeholder="请输入工号" clearable v-model="userName"></u--input>
  71. </view>
  72. <view class="form-area" style="padding:0 20rpx;margin-top: 20rpx;">
  73. <text class="form-label">新密码</text>
  74. <u--input placeholder="请输入新密码" clearable v-model="password"></u--input>
  75. </view>
  76. <view class="pwd-btn">
  77. <!-- <u-button size="small" @click="show = false">取消</u-button> -->
  78. <u-button type="primary" @click="resetPassword">重置密码</u-button>
  79. </view>
  80. </view>
  81. </u-popup>
  82. <u-toast ref="uToast" />
  83. </view>
  84. </template>
  85. <script>
  86. import cache from '@/utils/storage.js'
  87. import { sumBorrow } from '@/api/asset.js'
  88. import { uploadAvatar,logout,resetPwd } from '@/api/user.js'
  89. import { getImage } from '@/api/visitor.js'
  90. import { getToken } from '@/utils/auth';
  91. import baseUrl from '@/utils/baseurl.js'
  92. export default {
  93. data() {
  94. return {
  95. src: 'https://tupian.qqw21.com/article/UploadPic/2021-1/20211722215735941.jpg',
  96. avatar: '',
  97. name: "",
  98. amount:null,
  99. role:"",
  100. show: false,
  101. userName:"",
  102. password:"",
  103. token: ""
  104. };
  105. },
  106. methods:{
  107. handleUpImg() {// 点击图片区域,选择图片并上传
  108. const token = this.token
  109. let avatar = ""
  110. uni.chooseImage({// 选择图片
  111. count: 1,
  112. success: (res) => {// 图片选择成功的回调(必传),会返回一个对象
  113. // this.avatar = res.tempFilePaths[0] // 用于更新视图
  114. uni.uploadFile({
  115. url: baseUrl + "/system/user/profile/avatar", // 请求地址
  116. filePath: res.tempFilePaths[0], // 临时文件路径
  117. name: "avatarfile", // 文件对应的key值
  118. header: {
  119. Authorization: token // 需要带的请求头,token等等
  120. },
  121. formData: {// 额外的请求数据
  122. },
  123. success: (response) => {// 成功后的回调
  124. console.log('修改成功');
  125. const data = JSON.parse(response.data)
  126. cache.session.setJSON('avatar', data.imgUrl)
  127. this.avatar = data.imgUrl
  128. }
  129. })
  130. }
  131. })
  132. },
  133. close(){
  134. this.show = false
  135. },
  136. showPopup(){
  137. this.show = true
  138. this.userName = ""
  139. this.password = ""
  140. },
  141. imgSrc(src) {
  142. return getImage(src)
  143. },
  144. resetPassword(){
  145. if(this.userName.trim()===""){
  146. uni.showToast({
  147. icon:'error',
  148. title:'请输入工号'
  149. })
  150. return
  151. }
  152. if(this.password.trim()===""){
  153. uni.showToast({
  154. icon:'error',
  155. title:'请输入工号'
  156. })
  157. return
  158. }
  159. resetPwd(this.userName,this.password).then(res=>{
  160. if(res.data.code===200 && res.data.msg==="操作成功"){
  161. uni.showToast({
  162. icon:'success',
  163. title:'重置成功',
  164. duration:1000,
  165. success: () => {
  166. this.show = false
  167. }
  168. })
  169. }
  170. // console.log(res)
  171. })
  172. },
  173. toPersonInfo(){
  174. uni.navigateTo({
  175. url:'/pages/menus/mine/mine'
  176. })
  177. },
  178. toBorrowRecord(){
  179. uni.switchTab({
  180. url:'/pages/menus/borrow-record/borrow-record'
  181. })
  182. },
  183. init(){
  184. sumBorrow(0).then(res=>{
  185. this.amount = res
  186. })
  187. },
  188. toRepeat(){
  189. uni.scanCode({
  190. scanType:['barCode'],
  191. success (res) {
  192. uni.navigateTo({
  193. url:'/pages/fault/fault-report/fault-report?id='+res.result
  194. })
  195. }
  196. })
  197. },
  198. toHandleFault(){
  199. uni.navigateTo({
  200. url:'/pages/fault/fault-list/fault-list'
  201. })
  202. },
  203. toLogout(){
  204. //#ifdef MP-WEIXIN
  205. wx.showModal({
  206. title: '系统提示',
  207. content: '是否确认退出登录?',
  208. success (res) {
  209. uni.showLoading({
  210. title:'正在退出登录中',
  211. icon:'none',
  212. mask:true
  213. })
  214. if (res.confirm) {
  215. try{
  216. logout().then(res=>{
  217. if(res.data.code===200&&res.data.msg==="退出成功"){
  218. uni.hideLoading()
  219. uni.switchTab({
  220. url:'/pages/home/home'
  221. })
  222. }
  223. })
  224. }catch(err){
  225. uni.hideLoading()
  226. }
  227. } else if (res.cancel) {
  228. uni.hideLoading()
  229. console.log('用户点击取消')
  230. }
  231. }
  232. })
  233. //#endif
  234. //#ifndef MP-WEIXIN
  235. uni.showModal({
  236. title: '系统提示',
  237. content: '是否确认退出登录?',
  238. success (res) {
  239. uni.showLoading({
  240. title:'正在退出登录中',
  241. icon:'none',
  242. mask:true
  243. })
  244. if (res.confirm) {
  245. try{
  246. logout().then(res=>{
  247. if(res.data.code===200&&res.data.msg==="退出成功"){
  248. uni.hideLoading()
  249. uni.switchTab({
  250. url:'/pages/home/home'
  251. })
  252. }
  253. })
  254. }catch(err){
  255. uni.hideLoading()
  256. }
  257. } else if (res.cancel) {
  258. uni.hideLoading()
  259. console.log('用户点击取消')
  260. }
  261. }
  262. })
  263. //#endif
  264. }
  265. },
  266. onLoad() {
  267. this.init()
  268. },
  269. onShow(){
  270. this.init()
  271. this.name = cache.session.getJSON('nickName')
  272. this.role = cache.session.getJSON('role')
  273. this.avatar = cache.session.getJSON('avatar')
  274. this.token = `Bearer ${getToken()}`
  275. }
  276. }
  277. </script>
  278. <style lang="scss">
  279. .mine-area{
  280. // background-color: #225f15;
  281. // background-image: url('@/static/images/tsg02 (1).jpg');
  282. height: 100vh;
  283. position: relative;
  284. overflow: hidden;
  285. }
  286. .big-circle{
  287. width: 937px;
  288. height: 937px;
  289. background-color: rgba(255, 255, 255, 1);
  290. border-radius: 50%;
  291. position: absolute;
  292. top: 25%;
  293. left: 50%;
  294. transform: translate(-50%, 0);
  295. z-index: 5;
  296. }
  297. .avatar-area{
  298. position: absolute;
  299. top: 25%;
  300. left: 20%;
  301. transform: translateY(-50%);
  302. .img-boxs {
  303. width: 90px;
  304. height: 90px;
  305. border-radius: 100%;
  306. position: relative;
  307. overflow: hidden;
  308. box-shadow: 0 0 0 3px hsla(0,0%,100%,.9);
  309. }
  310. .img-boxs image {
  311. width: 90px;
  312. height: 90px;
  313. border-radius: 100%;
  314. margin-bottom: 10px;
  315. }
  316. .img-boxs cover-view {
  317. width: 90px;
  318. height: 30px;
  319. text-align: center;
  320. color: #fff;
  321. // background-color: rgba(107, 96, 99, .4);
  322. position: absolute;
  323. left: 50%;
  324. top: 76%;
  325. font-size: 26rpx;
  326. transform: translate(-50%, 0);
  327. }
  328. }
  329. .z10{
  330. z-index: 10;
  331. }
  332. .menu-area{
  333. height: 65%;
  334. width: 100%;
  335. position: absolute;
  336. bottom: 0;
  337. padding: 0 64rpx;
  338. box-sizing: border-box;
  339. }
  340. .menu-list{
  341. display: flex;
  342. align-items: center;
  343. font-size: 30rpx;
  344. padding: 20rpx 0 ;
  345. color: #323538;
  346. .iconfont{
  347. font-size: 65rpx;
  348. padding-right: 20rpx;
  349. }
  350. }
  351. .basic-msg{
  352. display: flex;
  353. margin-bottom: 40rpx;
  354. flex-direction: column;
  355. .basic-name{
  356. font-size: 32rpx;
  357. line-height: 150%;
  358. }
  359. .basic-amount{
  360. color: rgba(128, 128, 128, 1);
  361. font-size: 26rpx;
  362. line-height: 150%;
  363. }
  364. }
  365. .popup-area{
  366. height: 500rpx;
  367. box-sizing: border-box;
  368. padding: 0 30rpx;
  369. .form-area{
  370. display: flex;
  371. align-items: center;
  372. margin-top: 100rpx;
  373. .form-label{
  374. // padding: 0 20rpx 0 0;
  375. display: inline-block;
  376. width: 140rpx;
  377. text-align: left;
  378. }
  379. }
  380. .pwd-btn{
  381. display: flex;
  382. padding-top: 50rpx;
  383. /deep/.u-button{
  384. margin: 30rpx;
  385. }
  386. }
  387. }
  388. </style>