平安校园
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

197 satır
4.4 KiB

  1. <script>
  2. import http from '@/http/api.js'
  3. import {
  4. options
  5. } from '@/http/config.js';
  6. import {
  7. Base64
  8. } from '@/utils/base64.js';
  9. import {
  10. clientId,
  11. clientSecret
  12. } from '@/common/setting'
  13. export default{
  14. methods:{
  15. // 暂存一个跨页面变量 (与 this.GET_PARAM 成对使用)
  16. SET_PARAM(val) {
  17. this.SET_GLOBAL('pageParam', val)
  18. },
  19. // 获取之前暂存的跨页面变量 (与 this.SET_PARAM 成对使用)
  20. GET_PARAM() {
  21. return this.GET_GLOBAL('pageParam')
  22. },
  23. // 进入某个页面
  24. NAV_TO(url, param, usePageParam) {
  25. uni.navigateTo({
  26. url: this.handleNav(url, param, usePageParam)
  27. })
  28. },
  29. // 返回上个页面
  30. // delta 参数为返回的次数
  31. NAV_BACK(delta = 1) {
  32. uni.navigateBack({
  33. delta
  34. })
  35. },
  36. // 跳转到某个页面,跳转后无法返回
  37. JUMP_TO(url, param, usePageParam) {
  38. uni.redirectTo({
  39. url: this.handleNav(url, param, usePageParam)
  40. })
  41. },
  42. // 转到某个 Tab 页
  43. TAB_TO(url, param) {
  44. uni.switchTab({
  45. url: this.handleNav(url, param, true)
  46. })
  47. },
  48. // 【内部方法】处理页面跳转 url 和参数
  49. handleNav(url, param, usePageParam) {
  50. let query = ''
  51. if (param && usePageParam) {
  52. this.SET_PARAM(param)
  53. } else if (param && !usePageParam) {
  54. query += '?' + Object.entries(param).filter(([k, v]) => k && v).map(([k, v]) => k + '=' + v).join('&')
  55. }
  56. return url + query
  57. },
  58. // 设置页面标题
  59. SET_TITLE(title) {
  60. uni.setNavigationBarTitle({
  61. title
  62. })
  63. },
  64. // 监听一个全局事件
  65. ON(name, func) {
  66. uni.$on(name, func)
  67. },
  68. // 仅单次监听一个全局事件
  69. ONCE(name, func) {
  70. uni.$once(name, func)
  71. },
  72. // 触发一个全局事件
  73. EMIT(name, data) {
  74. uni.$emit(name, data)
  75. },
  76. // 移除全局事件监听器
  77. OFF(name, func) {
  78. uni.$off(name, func)
  79. },
  80. // 二次确认提示框
  81. CONFIRM(content='是否确认执行此操作?'){
  82. return new Promise((resolve)=>{
  83. uni.showModal({
  84. title: '提示信息',
  85. content: content,
  86. cancelText: "取消",
  87. confirmText: "确认",
  88. confirmColor: '#F2C827',
  89. cancelColor: '#9E9E9E',
  90. success: function (res) {
  91. if (res.confirm) {
  92. resolve(true)
  93. } else if (res.cancel) {
  94. resolve(false)
  95. }
  96. }
  97. });
  98. })
  99. },
  100. TOAST(title){
  101. uni.showToast({
  102. icon: "none",
  103. title,
  104. duration: 2000,
  105. });
  106. },
  107. UPLOAD_FILE(filePath){
  108. let that = this
  109. // 假设有token值需要在头部需要携带
  110. let header = {}
  111. let accessToken = uni.getStorageSync('accessToken');
  112. if (accessToken) {
  113. header['Blade-Auth'] = 'bearer ' + accessToken;
  114. }
  115. // 客户端认证参数
  116. header['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret);
  117. console.log(filePath)
  118. return new Promise(resovle=>{
  119. uni.uploadFile({
  120. url:options.baseURL + '/api/blade-resource/oss/endpoint/put-uplaod-file?bucketName=',
  121. filePath,
  122. name:'file',
  123. header,
  124. success(e){
  125. if(e.statusCode == 200){
  126. let res = JSON.parse(e.data)
  127. if(res.code == 200){
  128. resovle(res.data)
  129. }else{
  130. resovle(res.msg)
  131. }
  132. }else{
  133. resovle(false)
  134. }
  135. },
  136. fail(e){
  137. console.log('fail',e)
  138. resovle(false)
  139. },
  140. })
  141. })
  142. },
  143. DELETE_FILE(attachIds){
  144. return http.request({
  145. url: '/api/blade-resource/oss/endpoint/remove-file-attachIds',
  146. method: 'post',
  147. params:{attachIds}
  148. })
  149. },
  150. // 显示 loading 提示框
  151. // title 为提示文字
  152. // mask 为是否禁止点击
  153. LOADING(title, mask = true) {
  154. uni.showLoading({
  155. title,
  156. mask
  157. })
  158. },
  159. // 停止展示 loading 提示框
  160. HIDE_LOADING() {
  161. uni.hideLoading()
  162. },
  163. // url获取文件流
  164. DOWNLOAD_FILE(url){
  165. return uni.downloadFile({
  166. url
  167. })
  168. },
  169. //复制链接
  170. COPYLINK(item){
  171. return new Promise((resolve)=>{
  172. uni.setClipboardData({
  173. data: item, // 要复制的路径
  174. success: function(res) {
  175. resolve(true)
  176. // uni.getClipboardData({
  177. // success: function(data) {
  178. // resolve(true)
  179. // },
  180. // fail: function(data1) {
  181. // resolve(false)
  182. // }
  183. // });
  184. }
  185. });
  186. })
  187. },
  188. },
  189. }
  190. </script>