Browse Source

no message

WIN-8NDK4S1KEGQ\Administrator 3 years ago
parent
commit
992e416e03

+ 157 - 0
common/js/aliOssSts.js

@@ -0,0 +1,157 @@
+/**
+ * 微信小程序通过STS直传阿里云OSS
+ *(uniapp版上传,小程序原生需要将uni.XXX替换为wx.XXX)
+ *
+ * @param {filePath} 图片临时地址
+ * @param {option|Object} OSS和STS配置
+ * @param {savePath} oss中的文件目录
+ * @param {AccessKeySecret} 服务端返回的STS中的AccessKeySecret
+ * @param {SecurityToken} 服务端返回的STS中的SecurityToken
+ * @param {AccessKeyId} 服务端返回的STS中的AccessKeyId
+ * @param {bucket} 存储桶
+ * @param {area} 地区
+ * @return {string|boolean} 成功返回文件地址,失败返回false
+ */
+
+import crypto from 'crypto-js';
+import {Base64} from 'js-base64/base64.js';
+
+function upload(filePath, option = {
+    savePath,
+    AccessKeySecret,
+    SecurityToken,
+    AccessKeyId,
+    bucket,
+    area
+}, callBack = () => {}) {
+    let fileType = filePath.split(".").pop();
+    let filename = option.savePath + "/" + createFileName(32) + "." + fileType;
+
+
+    const date = new Date();
+    date.setHours(date.getHours() + 1);
+    const policyText = {
+        expiration: date.toISOString(), // 设置policy过期时间。
+        conditions: [
+            ["content-length-range", 0, 1024 * 1024 * 1024],
+        ],
+    };
+    const policy = Base64.encode(JSON.stringify(policyText)) // policy必须为base64的string。
+    const signature = computeSignature(option.AccessKeySecret, policy)
+    const formData = {
+        OSSAccessKeyId: option.AccessKeyId,
+        signature,
+        policy,
+        'x-oss-security-token': option.SecurityToken,
+        key: filename,
+        success_action_status: 200
+    }
+
+    uni.uploadFile({
+        url: "https://" + option.bucket +
+            "." + option.area + ".aliyuncs.com",
+        filePath: filePath,
+        name: "file",
+        formData: formData,
+        success: (res) => {
+            let ossFileName = false;
+            if (res.statusCode === 200) {
+                // console.log('上传成功');
+                ossFileName = "https://" + option.bucket +
+                    "." + option.area + ".aliyuncs.com/" +
+                    filename;
+            }
+            callBack(ossFileName);
+        },
+        fail: err => {
+            // console.log(err);
+            callBack(false);
+        }
+    })
+}
+
+// 签名
+function computeSignature(accessKeySecret, canonicalString) {
+    return crypto.enc.Base64.stringify(crypto.HmacSHA1(canonicalString, accessKeySecret));
+}
+
+// 生成随机文件名
+function createFileName(length) {
+    const data = [
+        "0",
+        "1",
+        "2",
+        "3",
+        "4",
+        "5",
+        "6",
+        "7",
+        "8",
+        "9",
+        "A",
+        "B",
+        "C",
+        "D",
+        "E",
+        "F",
+        "G",
+        "H",
+        "I",
+        "J",
+        "K",
+        "L",
+        "M",
+        "N",
+        "O",
+        "P",
+        "Q",
+        "R",
+        "S",
+        "T",
+        "U",
+        "V",
+        "W",
+        "X",
+        "Y",
+        "Z",
+        "a",
+        "b",
+        "c",
+        "d",
+        "e",
+        "f",
+        "g",
+        "h",
+        "i",
+        "j",
+        "k",
+        "l",
+        "m",
+        "n",
+        "o",
+        "p",
+        "q",
+        "r",
+        "s",
+        "t",
+        "u",
+        "v",
+        "w",
+        "x",
+        "y",
+        "z",
+    ];
+    let nums = "";
+    for (let i = 0; i < length; i++) {
+        const r = parseInt(Math.random() * 61, 10);
+        nums += data[r];
+    }
+    return nums;
+}
+
+
+
+
+export default {
+    upload
+}

+ 43 - 0
common/js/upLoadingFile.js

@@ -0,0 +1,43 @@
+// import {
+// 	getSts
+// } from "@/api/common.js";
+import tools from "./tools";
+import AliOss from "./aliOssSts.js";
+
+let ossData = null;
+let sysTime = 0;
+let setAliSts = async function () {
+	let res = await getSts({});
+	if (res.code === 1) {
+		ossData = res.data;
+		sysTime = setTime();
+	} else {
+		tools.error(res.msg);
+	}
+}
+
+let setTime = function () {
+	return (new Date()).getTime();
+}
+let getFilPathName = function () {
+	let date = new Date();
+	return "image/" + date.getYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
+}
+
+export const upLoadingFileOss = async function (file) {
+	if (ossData === null || (sysTime + 900000 <= setTime())) {
+		await setAliSts();
+	}
+	return new Promise((resolve, reject) => {
+		AliOss.upload(file, {
+			savePath: getFilPathName(),
+			AccessKeySecret: ossData.AccessKeySecret,
+			SecurityToken: ossData.SecurityToken,
+			AccessKeyId: ossData.AccessKeyId,
+			bucket: "jhnewshop",
+			area: "oss-cn-chengdu",
+		}, function (res) {
+			resolve(res);
+		});
+	});
+}

+ 57 - 27
components/en-list/en-list.vue

@@ -1,36 +1,66 @@
 <template>
-  <view class="box">
-
-  </view>
+	<view class="list">		
+		<Blank v-if="false"></Blank>
+		<view class="scroll-view" v-else>
+			<scroll-view scroll-y="true" style="height: 100%;" @scrolltolower="onReachScollBottom">
+				<slot name="listInfo"></slot>
+				<view class="toMore" v-show="list.length<this.total">加载更多</view>
+			</scroll-view>
+		</view>
+		
+	</view>
 </template>
 
 <script>
-export default {
-  name: 'en-list',
-  props: {
-
-  },
-  data() {
-    return {
-
-    }
-  },
-  components: {
-
-  },
-  mounted() {
+	import Black from '@/components/en-utils/en-blank.vue'
 
-  },
-  watch: {
+	export default {
+		components: {Blank},
+		data() {
+			return {
+				list:[],
+				page:1,
+				total:null,
+				status:'',
+			}
+		},
+		mounted() {
 
-  },
-  methods: {
-
-  }
-
-}
+		},
+		methods:{
+			onReachScollBottom(){
+				if(this.list.length == this.total){
+					return
+				}else{
+					
+				}
+			},
+		},
+	}
 </script>
 
-<style lang="scss" scoped>
-
+<style scoped lang="scss">
+	.list{
+		height: 100%;
+		display: flex;
+		flex-direction: column;
+		.scroll-view{
+			flex: 1;
+			overflow: auto;
+		}
+		.toMore{
+			color: #999;
+			font-size: 20rpx;
+			margin: 25rpx 0;
+			text-align: center;
+		}
+		::-webkit-scrollbar {
+			display: none;
+			width: 0;
+			height: 0;
+			background-color: transparent;
+		}
+		
+		
+	}
 </style>

+ 1 - 1
components/en-utils/en-blank.vue

@@ -2,7 +2,7 @@
 	<view class="blank-page" v-if="showBlank">
 		<view class="blank-img-box">
 			<slot name="blankImg">
-				<image src="../static/img/blank-box.svg" class="blank-img"></image>
+				<image src="@/static/img/blank-box.svg" class="blank-img"></image>
 			</slot>
 		</view>
 		<view class="blank-text">

+ 100 - 0
components/en-utils/en-head-img.vue

@@ -0,0 +1,100 @@
+<template>
+	<view>
+		<view class="box" @click="editImg()">
+			<image class="left" :src="value" mode="aspectFill"></image>
+			<view class="right">
+				<text>{{label}}</text>
+				<image src="@/static/img/toRight.png" mode=""></image>
+			</view>
+		</view>
+		<uni-popup>
+			
+		</uni-popup>
+	</view>
+</template>
+
+<script>
+	import { upLoadingFileOss } from "@/common/js/upLoadingFile";
+	
+	export default {
+		props:{
+			label: {
+			  type: String,
+			  default: '标题'
+			},
+			value:{
+				type: String,
+				default: ''
+			},
+		},
+		data(){
+			return{
+				
+			}
+		},
+		methods:{
+			showsdasa(){
+				let isH5=false
+				// #ifdef H5
+				isH5=true
+				// #endif
+				if(isH5){
+					this.editImg(1)
+				}else{
+					
+				}
+			},
+			editImg(type){
+				uni.chooseImage({
+					count: 1,
+					sizeType: ["compressed", "camera"],
+					sourceType: [type===1?"album":"camera"],
+					success:(res)=>{
+						if (res.errMsg == "chooseImage:ok"){
+							this.upLoadOss(res.tempFiles[0].path)
+						}else{
+							// tools.error('头像选择失败')
+						}
+					}
+				})
+			},
+			
+			upLoadOss(path){
+				let url = upLoadingFileOss(path)
+				
+				console.log(url);
+			},
+		},
+	}
+</script>
+
+<style scoped lang="scss">
+	.box{
+		width: 100%;
+		height: 152rpx;
+		background-color: #fff;
+		display: flex;
+		align-items: center;
+		justify-content: space-between;
+		image{
+			width: 96rpx;
+			height: 96rpx;
+			border-radius: 50%;
+		}
+		.left{
+			font-size: 32rpx;
+		}
+		.right{
+			display: flex;
+			align-items: center;
+			text{
+				font-size: 32rpx;
+				color: #333;
+			}
+			image{
+				width: 40rpx;
+				height: 40rpx;
+			}
+		}
+	}
+</style>

+ 93 - 71
pages/index/index.vue

@@ -1,87 +1,108 @@
 <template>
 	<view class="box-data">
-    <Nav title="首页"></Nav>
-    <view class="border-item"></view>
-    <enInput v-model="text" label="姓名姓名"></enInput>
-    <enSend v-model="phone" ref="enSendObj" @getCode="getCode"></enSend>
-    <enCheckbox v-model="type"  label="爱好爱好" :checkboxData="checkboxData"></enCheckbox>
-    <enRadio v-model="sex"  label="性别性别" :radioData="radioData"></enRadio>
-    <enSwitch v-model="status"  label="状态试" ></enSwitch>
-    <enTextarea v-model="content" label="个人简介"></enTextarea>
-    <enDate v-model="birthday" type="datetime" label="生日生日"></enDate>
-	
-	
-	<view class="" @click="toList()">进入列表演示</view>
-  </view>
+		<Nav title="首页"></Nav>
+		<view class="border-item"></view>
+		<enInput v-model="text" label="姓名姓名"></enInput>
+		<enSend v-model="phone" ref="enSendObj" @getCode="getCode"></enSend>
+		<enCheckbox v-model="type" label="爱好爱好" :checkboxData="checkboxData"></enCheckbox>
+		<enRadio v-model="sex" label="性别性别" :radioData="radioData"></enRadio>
+		<enSwitch v-model="status" label="状态试"></enSwitch>
+		<enTextarea v-model="content" label="个人简介"></enTextarea>
+		<enDate v-model="birthday" type="datetime" label="生日生日"></enDate>
+
+		<enHeadImg v-model="img" label="修改头像"></enHeadImg>
+
+
+		<view class="" @click="toList()">进入列表演示</view>
+	</view>
 
 </template>
 <script>
+	import enInput from "components/en-from/en-input/en-input"
+	import enSend from "components/en-from/en-send/en-send"
+	import enCheckbox from "components/en-from/en-checkbox/en-checkbox"
+	import enRadio from "components/en-from/en-radio/en-radio"
+	import enSwitch from "components/en-from/en-switch/en-switch"
+	import enTextarea from "components/en-from/en-textarea/en-textarea"
+	import enDate from "components/en-from/en-date/en-date"
+	import enHeadImg from "@/components/en-utils/en-head-img.vue"
 
-  import enInput from "components/en-from/en-input/en-input"
-  import enSend from "components/en-from/en-send/en-send"
-  import enCheckbox from "components/en-from/en-checkbox/en-checkbox"
-  import enRadio from "components/en-from/en-radio/en-radio"
-  import enSwitch from "components/en-from/en-switch/en-switch"
-  import enTextarea from "components/en-from/en-textarea/en-textarea"
-  import enDate from "components/en-from/en-date/en-date"
 	export default {
 		components: {
-      enDate,
-      enTextarea,
-      enSwitch,
-      enRadio,
-      enCheckbox,
-      enInput,
-      enSend
+			enDate,
+		 enTextarea,
+		 enSwitch,
+			enRadio,
+			enCheckbox,
+			enInput,
+			enSend,
+			enHeadImg
 		},
 		data() {
 			return {
-        phone:'13900139001',
-        birthday:'',
-        text:'来自火星的你',
-        content:'你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?',
-        type:['1'],
-        sex:'1',
-        status:1,
-        // checkboxData:[{'id':'1','name':'足球'},{'id':'2','name':'篮球'},{'id':'3','name':'排球'},{'id':'4','name':'羽毛球'},{'id':'5','name':'乒乓球'},{'id':'6','name':'铅球'},{'id':'7','name':'棒球'},{'id':'8','name':'冰球'},{'id':'9','name':'网球'},{'id':'10','name':'乒乓球'}]
-        checkboxData:[{'id':'1','name':'足球'},{'id':'2','name':'篮球'},{'id':'3','name':'排球'}],
-        radioData:[{'id':'1','name':'男'},{'id':'2','name':'女'}]
+				img:require('@/static/img/2.jpg'),
+				
+				phone: '13900139001',
+				birthday: '',
+				text: '来自火星的你',
+				content: '你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?你会火星语吗?',
+				type: ['1'],
+				sex: '1',
+				status: 1,
+				// checkboxData:[{'id':'1','name':'足球'},{'id':'2','name':'篮球'},{'id':'3','name':'排球'},{'id':'4','name':'羽毛球'},{'id':'5','name':'乒乓球'},{'id':'6','name':'铅球'},{'id':'7','name':'棒球'},{'id':'8','name':'冰球'},{'id':'9','name':'网球'},{'id':'10','name':'乒乓球'}]
+				checkboxData: [{
+					'id': '1',
+					'name': '足球'
+				}, {
+					'id': '2',
+					'name': '篮球'
+				}, {
+					'id': '3',
+					'name': '排球'
+				}],
+				radioData: [{
+					'id': '1',
+					'name': '男'
+				}, {
+					'id': '2',
+					'name': '女'
+				}]
 			}
 		},
-    watch:{
-      'birthday':function (){
-        console.log('new--------birthday',this.birthday)
-      },
-      'content':function (){
-        console.log('new--------content',this.content)
-      },
-      'type':function (){
-        console.log('new--------type',this.type)
-      },
-		  'phone':function (){
-        console.log('new--------'+this.phone)
-      },
-      'text':function (){
-        console.log('new--------'+this.text)
-      },
-      'status':function (){
-        console.log('new--------'+this.status)
-      }
+		watch: {
+			'birthday': function() {
+				console.log('new--------birthday', this.birthday)
+			},
+			'content': function() {
+				console.log('new--------content', this.content)
+			},
+			'type': function() {
+				console.log('new--------type', this.type)
+			},
+			'phone': function() {
+				console.log('new--------' + this.phone)
+			},
+			'text': function() {
+				console.log('new--------' + this.text)
+			},
+			'status': function() {
+				console.log('new--------' + this.status)
+			}
 
-    },
+		},
 
 		mounted() {
 
 		},
 		methods: {
-		  getCode(){
-			console.log('---------------------asdsa')
-			this.text='abc'
-			this.$refs.enSendObj.setCodeNum()
-		  },
-			toList(){
+			getCode() {
+				console.log('---------------------asdsa')
+				this.text = 'abc'
+				this.$refs.enSendObj.setCodeNum()
+			},
+			toList() {
 				uni.navigateTo({
-					url:'/pages/text/index'
+					url: '/pages/text/index'
 				})
 			},
 
@@ -89,11 +110,12 @@
 	}
 </script>
 <style lang="scss" scoped>
-.border-item{
-  border-bottom: 2rpx solid #F0F0F0;
-}
-.box-data{
-  padding: 32rpx 32rpx 0;
-  background-color: #fff;
-}
+	.border-item {
+		border-bottom: 2rpx solid #F0F0F0;
+	}
+
+	.box-data {
+		padding: 32rpx 32rpx 0;
+		background-color: #fff;
+	}
 </style>

+ 15 - 5
pages/text/index.vue

@@ -1,16 +1,26 @@
 <template>
 	<view>
-		<Nav title="列表组件演示"></Nav>
-		<Black></Black>
+		<Nav title="列表组件演示" @leftClick='toBack'></Nav>
+		<!-- <enList>
+			<view :slot="listInfo">插入不同样式的内容</view>
+		</enList> -->
 	</view>
 </template>
 
 <script>
-	import Black from '@/components/en-utils/en-blank.vue'
+	// import enList from '../../components/en-list/en-list.vue'
 	
 	export default {
-		components:{
-			Black,
+		// components:{enList,},
+		data(){
+			return{}
+		},
+		methods:{
+			toBack() {
+				uni.navigateBack({
+					delta: 1,
+				})
+			},
 		},
 	}
 </script>

BIN
static/img/2.jpg


+ 0 - 0
components/static/img/blank-box.svg → static/img/blank-box.svg


BIN
static/img/toRight.png