menu.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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">
  7. <image :src="avatar.length > 0 ? imgSrc(avatar) : src" @click="handleUpImg"></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. const data = JSON.parse(response.data)
  125. cache.session.setJSON('avatar', data.imgUrl)
  126. this.avatar = data.imgUrl
  127. }
  128. })
  129. }
  130. })
  131. },
  132. close(){
  133. this.show = false
  134. },
  135. showPopup(){
  136. this.show = true
  137. this.userName = ""
  138. this.password = ""
  139. },
  140. imgSrc(src) {
  141. return getImage(src)
  142. },
  143. resetPassword(){
  144. if(this.userName.trim()===""){
  145. uni.showToast({
  146. icon:'error',
  147. title:'请输入工号'
  148. })
  149. return
  150. }
  151. if(this.password.trim()===""){
  152. uni.showToast({
  153. icon:'error',
  154. title:'请输入工号'
  155. })
  156. return
  157. }
  158. resetPwd(this.userName,this.password).then(res=>{
  159. if(res.data.code===200 && res.data.msg==="操作成功"){
  160. uni.showToast({
  161. icon:'success',
  162. title:'重置成功',
  163. duration:1000,
  164. success: () => {
  165. this.show = false
  166. }
  167. })
  168. }
  169. // console.log(res)
  170. })
  171. },
  172. toPersonInfo(){
  173. uni.navigateTo({
  174. url:'/pages/menus/mine/mine'
  175. })
  176. },
  177. toBorrowRecord(){
  178. uni.switchTab({
  179. url:'/pages/menus/borrow-record/borrow-record'
  180. })
  181. },
  182. init(){
  183. sumBorrow(0).then(res=>{
  184. this.amount = res
  185. })
  186. },
  187. toRepeat(){
  188. uni.scanCode({
  189. scanType:['barCode'],
  190. success (res) {
  191. uni.navigateTo({
  192. url:'/pages/fault/fault-report/fault-report?id='+res.result
  193. })
  194. }
  195. })
  196. },
  197. toHandleFault(){
  198. uni.navigateTo({
  199. url:'/pages/fault/fault-list/fault-list'
  200. })
  201. },
  202. toLogout(){
  203. //#ifdef MP-WEIXIN
  204. wx.showModal({
  205. title: '系统提示',
  206. content: '是否确认退出登录?',
  207. success (res) {
  208. uni.showLoading({
  209. title:'正在退出登录中',
  210. icon:'none',
  211. mask:true
  212. })
  213. if (res.confirm) {
  214. try{
  215. logout().then(res=>{
  216. if(res.data.code===200&&res.data.msg==="退出成功"){
  217. uni.hideLoading()
  218. uni.switchTab({
  219. url:'/pages/home/home'
  220. })
  221. }
  222. })
  223. }catch(err){
  224. uni.hideLoading()
  225. }
  226. } else if (res.cancel) {
  227. uni.hideLoading()
  228. console.log('用户点击取消')
  229. }
  230. }
  231. })
  232. //#endif
  233. //#ifndef MP-WEIXIN
  234. uni.showModal({
  235. title: '系统提示',
  236. content: '是否确认退出登录?',
  237. success (res) {
  238. uni.showLoading({
  239. title:'正在退出登录中',
  240. icon:'none',
  241. mask:true
  242. })
  243. if (res.confirm) {
  244. try{
  245. logout().then(res=>{
  246. if(res.data.code===200&&res.data.msg==="退出成功"){
  247. uni.hideLoading()
  248. uni.switchTab({
  249. url:'/pages/home/home'
  250. })
  251. }
  252. })
  253. }catch(err){
  254. uni.hideLoading()
  255. }
  256. } else if (res.cancel) {
  257. uni.hideLoading()
  258. console.log('用户点击取消')
  259. }
  260. }
  261. })
  262. //#endif
  263. }
  264. },
  265. onLoad() {
  266. this.init()
  267. },
  268. onShow(){
  269. this.init()
  270. this.name = cache.session.getJSON('nickName')
  271. this.role = cache.session.getJSON('role')
  272. this.avatar = cache.session.getJSON('avatar')
  273. this.token = `Bearer ${getToken()}`
  274. }
  275. }
  276. </script>
  277. <style lang="scss">
  278. .mine-area{
  279. // background-color: #225f15;
  280. // background-image: url('@/static/images/tsg02 (1).jpg');
  281. height: 100vh;
  282. position: relative;
  283. overflow: hidden;
  284. }
  285. .big-circle{
  286. width: 937px;
  287. height: 937px;
  288. background-color: rgba(255, 255, 255, 1);
  289. border-radius: 50%;
  290. position: absolute;
  291. top: 25%;
  292. left: 50%;
  293. transform: translate(-50%, 0);
  294. z-index: 5;
  295. }
  296. .avatar-area{
  297. position: absolute;
  298. top: 25%;
  299. left: 20%;
  300. transform: translateY(-50%);
  301. .img-boxs {
  302. width: 90px;
  303. height: 90px;
  304. border-radius: 100%;
  305. position: relative;
  306. overflow: hidden;
  307. box-shadow: 0 0 0 3px hsla(0,0%,100%,.9);
  308. }
  309. .img-boxs image {
  310. width: 90px;
  311. height: 90px;
  312. border-radius: 100%;
  313. margin-bottom: 10px;
  314. }
  315. .img-boxs cover-view {
  316. width: 90px;
  317. height: 30px;
  318. text-align: center;
  319. color: #fff;
  320. background-color: rgba(107, 96, 99, .4);
  321. position: absolute;
  322. left: 50%;
  323. top: 76%;
  324. font-size: 26rpx;
  325. transform: translate(-50%, 0);
  326. }
  327. }
  328. .z10{
  329. z-index: 10;
  330. }
  331. .menu-area{
  332. height: 65%;
  333. width: 100%;
  334. position: absolute;
  335. bottom: 0;
  336. padding: 0 64rpx;
  337. box-sizing: border-box;
  338. }
  339. .menu-list{
  340. display: flex;
  341. align-items: center;
  342. font-size: 30rpx;
  343. padding: 20rpx 0 ;
  344. color: #323538;
  345. .iconfont{
  346. font-size: 65rpx;
  347. padding-right: 20rpx;
  348. }
  349. }
  350. .basic-msg{
  351. display: flex;
  352. margin-bottom: 40rpx;
  353. flex-direction: column;
  354. .basic-name{
  355. font-size: 32rpx;
  356. line-height: 150%;
  357. }
  358. .basic-amount{
  359. color: rgba(128, 128, 128, 1);
  360. font-size: 26rpx;
  361. line-height: 150%;
  362. }
  363. }
  364. .popup-area{
  365. height: 500rpx;
  366. box-sizing: border-box;
  367. padding: 0 30rpx;
  368. .form-area{
  369. display: flex;
  370. align-items: center;
  371. margin-top: 100rpx;
  372. .form-label{
  373. // padding: 0 20rpx 0 0;
  374. display: inline-block;
  375. width: 140rpx;
  376. text-align: left;
  377. }
  378. }
  379. .pwd-btn{
  380. display: flex;
  381. padding-top: 50rpx;
  382. /deep/.u-button{
  383. margin: 30rpx;
  384. }
  385. }
  386. }
  387. </style>