123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- /**
- * 显示消息提示框
- * @param content 提示的标题
- */
- import config from '@/config'
- const baseUrl = config.baseUrl
- import {
- getAccessToken
- } from '@/utils/auth'
- import loadImage from 'blueimp-load-image';
- export function toast(content) {
- uni.showToast({
- icon: 'none',
- title: content
- })
- }
- /**
- * 显示模态弹窗
- * @param content 提示的标题
- */
- export function showConfirm(content) {
- return new Promise((resolve, reject) => {
- uni.showModal({
- title: '提示',
- content: content,
- cancelText: '取消',
- confirmText: '确定',
- success: function(res) {
- resolve(res)
- }
- })
- })
- }
- /**
- * 参数处理
- * @param params 参数
- */
- export function tansParams(params) {
- let result = ''
- for (const propName of Object.keys(params)) {
- const value = params[propName]
- var part = encodeURIComponent(propName) + "="
- if (value !== null && value !== "" && typeof(value) !== "undefined") {
- if (typeof value === 'object') {
- for (const key of Object.keys(value)) {
- if (value[key] !== null && value[key] !== "" && typeof(value[key]) !== 'undefined') {
- let params = propName + '[' + key + ']'
- var subPart = encodeURIComponent(params) + "="
- result += subPart + encodeURIComponent(value[key]) + "&"
- }
- }
- } else {
- result += part + encodeURIComponent(value) + "&"
- }
- }
- }
- return result
- }
- //获取检查项类型
- export function checkType(dictTypeData, dictTypeValue) {
- let name = []
- const data = uni.getStorageSync('getlistSimpleDict_key')
- data.map(v => {
- if (dictTypeData == v.dictType && dictTypeValue == v.value) {
- name = v.label
- }
- })
- return name
- }
- //时间戳转换为年月日
- export function shijianc(time) {
- let date = new Date(time)
- let Y = date.getFullYear() + '-'
- let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
- let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
- let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
- let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
- let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
- return Y + M + D + h + m + s
- }
- //删除
- export function delSure(delInterface, val, context) {
- uni.showModal({
- title: '确认删除',
- content: `是否确认删除?`,
- success: function(res) {
- console.log(res, 'res');
- if (res.confirm) {
- delInterface({
- id: val
- }).then(delres => {
- context.$modal.msg('删除成功')
- })
- } else if (res.cancel) {
- context.$modal.msg('取消删除')
- }
- context.loading = true;
- context.isLoaded = false
- context.queryParams.pageNo = 1;
- context.list = []
- context.getData()
- }
- });
- }
- //9个表的输入框规则
- export function NumericRule() {
- return [{
- pattern: /^[0-9]+$/,
- message: '请输入数字',
- trigger: ['change', 'blur'],
- }];
- }
- //拍照npm install blueimp-load-image
- export function takePhotos(vm) {
- let pictures = [];
- uni.chooseImage({
- sourceType: ['camera'], //实现拍照
- count: 3,
- sizeType: ['original', 'compressed'],
- // sourceType: ['album','camera'], //打开系统相册
- success(res) {
- if (res.tempFilePaths.length === 0) {
- vm.loading = false;
- return;
- }else{
- vm.loading=true
- }
- if (Array.isArray(res.tempFilePaths)) {
- res.tempFilePaths.forEach(item => {
- loadImage(
- item,
- function(canvas) {
- canvas.toBlob(function(blob) {
- // 压缩后的 Blob 对象
- const compressedFile = blob;
- // 将压缩后的文件 `compressedFile` 转换为临时URL
- const fileUrl = URL.createObjectURL(compressedFile);
- // 接下来将临时URL作为文件路径上传到服务器
- uni.uploadFile({
- url: baseUrl + '/admin-api/infra/file/upload',
- filePath: fileUrl, // 使用临时URL作为文件路径
- name: 'file',
- header: {
- "Authorization": 'Bearer ' +
- getAccessToken(),
- },
- success: (res) => {
- vm.loading = false
- let imgUrl = JSON.parse(res.data);
- vm.formData.streetRepPicsDOList.push({
- url: imgUrl.data,
- feildname: '',
- repid: ''
- });
- vm.$forceUpdate();
- },
- fail: (err) => {
- vm.loading = false
- this.$modal.msg(err)
- },
- complete: () => {
- vm.loading =
- false; // 无论成功还是失败,都将loading状态设置为false
- vm.$forceUpdate();
- }
- });
- // 上传完毕后,释放临时URL
- URL.revokeObjectURL(fileUrl);
- }, 'image/jpeg', 0.6); // 设置压缩后的图片格式为 JPEG,压缩质量为 0.6
- }, {
- canvas: true,
- maxWidth: 800
- } // 设置最大宽度为 800px
- );
- });
- }
- },
- fail: (err) => {
- vm.loading = false;
- },
- })
- }
- export function choiceStreet(vm) {
- const deptValue = uni.getStorageSync('getDepartment_key'); //所有部门
- const deptId = uni.getStorageSync('getUserInfo_key').streetInfo ? uni.getStorageSync('getUserInfo_key').streetInfo
- .id : ''; //登录用户
- var newArrar = {}; //新对象
- if (deptId) {
- console.log(deptValue, 'deptValue部门', deptId);
- newArrar = deptValue.find((item) => {
- if (item.id === deptId) {
- console.log(vm.formData.streetName, ' this.formData.streetName');
- vm.formData.streetId = item.id;
- vm.formData.streetName = item.qumc;
- } else {
- vm.actionsStreet.push({
- id: item.id,
- name: item.qumc
- });
- vm.actionsMaplist = vm.splitArray(vm.actionsStreet, 9);
- }
- })
- // show1 ='0' 点击将不再显示弹窗
- vm.show1 = '0'
- }
- }
- // 下载附件
- export function downSee(appendix) {
- const fileExt = appendix.substring(appendix.lastIndexOf('.') + 1);
- //加载框动画
- uni.showLoading({
- title: '正在下载……'
- });
- // #ifdef H5
- if (fileExt === 'png' || fileExt === 'jpg') {
- // 预览图片
- uni.previewImage({
- urls: [appendix],
- // longPressActions: {
- // itemList: ['发送给朋友', '保存图片', '收藏'],
- success: function(data) {
- console.log(data, 'dataaaaaaaaaaaa');
- uni.hideLoading();
- },
- fail: function(err) {
- console.log(err.errMsg);
- }
- // }
- })
- } else {
- const link = document.createElement('a');
- link.href = appendix;
- link.download = appendix;
- document.body.appendChild(link);
- link.click();
- link.remove();
- uni.hideLoading();
- uni.showToast({
- icon: 'success',
- mask: true,
- title: '文件已下载',
- duration: 2000
- });
- }
- // #endif
- // #ifdef MP-WEIXIN
- uni.downloadFile({
- url: appendix, //下载地址接口返回
- success: data => {
- // console.log('打印data', data);
- if (data.statusCode === 200) {
- //隐藏加载框
- // uni.hideLoading();
- //文件保存到本地
- uni.getFileSystemManager().saveFile({
- tempFilePath: data.tempFilePath, //临时路径
- success: function(res) {
- // console.log('打印res', res);
- uni.showToast({
- icon: 'success',
- mask: true,
- title: '文件已保存:' + res.savedFilePath, //保存路径
- title: '加载成功',
- duration: 2000
- });
- //自动打开文档查看
- setTimeout(() => {
- var filePath = res.savedFilePath;
- console.log(res, 'filePathfilePath');
- uni.openDocument({
- //新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。
- filePath: filePath,
- fileType: fileExt,
- showMenu: false,
- success: function(res) {
- console.log('打开文档成功');
- },
- fail: function() {
- uni.showToast({
- title: '暂不支持打开此类型',
- duration: 2000,
- icon: 'none'
- });
- }
- });
- }, 1000);
- }
- });
- }
- },
- fail: err => {
- console.log(err);
- uni.showToast({
- icon: 'none',
- mask: true,
- title: '文件下载失败'
- });
- }
- }) // #endif
- }
- export function uploadFile(tempFilePaths, i, that) {
- return new Promise((resolve, reject) => {
- const loading = uni.showLoading({
- title: '文件上传中...',
- mask: true
- });
- uni.uploadFile({
- url: baseUrl + '/admin-api/infra/file/upload', // 后端用于处理图片并返回图片地址及文件的接口
- filePath: tempFilePaths[i],
- name: 'file',
- header: {
- Authorization: 'Bearer ' + getAccessToken() // 请求token
- },
- success: res => {
- let data = JSON.parse(res.data);
-
- // that.formData.attId.push(data.data)
- that.formData.attId=['']
- that.formData.attId[0] = data.data
- uni.showToast({
- title: '文件上传成功!'
- });
- that.loading = false
- },
- fail: err => {
- uni.showToast({
- icon: 'error',
- title: '文件上传失败!'
- });
- that.loading = false
- },
- complete: () => {
- uni.hideLoading(loading);
- }
- });
- });
- }
|