微信小程序仿朋友圈 上传图片 定位

Posted CoKeny

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信小程序仿朋友圈 上传图片 定位相关的知识,希望对你有一定的参考价值。

           

   两个页面  ,,上面是效果图!!!!

  以下代码有部分是开发时用到的代码,懒的删了。不需要的自行删除

    代码如下 :

   

//index.wxml  发布页面

<form bindsubmit="formSubmit">
  <view class="section">
    <textarea bindblur="bindTextAreaBlur" auto-height placeholder="这一刻的想法..." style="margin-top:20rpx;margin-left:20rpx;width:680rpx;" name="textarea" />
  </view>
  <view class="container" style="padding-top:40rpx;float:left;padding-bottom:0;">
    <view class="page-body" style="float:left;">
      <view class="page-section">
        <view class="weui-cells weui-cells_after-title">
        </view>
        <view class="weui-cells">
          <view class="weui-cell">
            <view class="weui-cell__bd">
              <view class="weui-uploader">
                <view class="weui-uploader__hd">
                  <view class="weui-uploader__title">已选择的照片</view>
                  <view class="weui-uploader__info">{{imageList.length}}/{{count[countIndex]}}</view>
                </view>
                <view class="weui-uploader__bd">
                  <view class="weui-uploader__files">
                    <block wx:for="{{imageList}}" wx:for-item="image">
                      <view class="weui-uploader__file">
                        <image class="weui-uploader__img" src="{{image}}" data-src="{{image}}" bindtap="previewImage"></image>
                      </view>
                    </block>
                    <view class="weui-uploader__input-box">
                      <view class="weui-uploader__input" bindtap="chooseImage"></view>
                    </view>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
  <view style="border-bottom:1rpx solid #ccc;width:100%;float:left;margin-left:30rpx;"></view>
  <view class="page-body" style="float:left;width:100%;border-bottom:1rpx solid #ccc;">
    <view class="page-section">
      <view class="page-body-info" bindtap="chooseLocation">
        <block wx:if="{{hasLocation === false}}">
          <image src="https://www.caohi.cn/api/image/llsq_location_grey.png" class="page-body-img"></image>
          <text class="page-body-text" name="address">所在位置</text>
          <image src="https://www.caohi.cn/api/image/llsq_location_zk.png" class="page-body-img-zk"></image>
        </block>
        <block wx:if="{{hasLocation === true}}">
          <image src="https://www.caohi.cn/api/image/llsq_location_green.png" class="page-body-img"></image>
          <text class="page-body-text" name="address">{{locationAddress}}</text>
        </block>
      </view>
    </view>
  </view>
  <view style="float:left;width:100%;">
    <button id="mini-btn" type="primary" size="mini" form-type="submit">发送</button>
  </view>
</form>
//index.js

var util = require(\'../../utils/util.js\') var formatLocation = util.formatLocation var sourceType = [ [\'camera\'], [\'album\'], [\'camera\', \'album\'] ] var sizeType = [ [\'compressed\'], [\'original\'], [\'compressed\', \'original\'] ] Page({ data: { imageList: [], sourceTypeIndex: 2, sourceType: [\'拍照\', \'相册\', \'拍照或相册\'], sizeTypeIndex: 2, sizeType: [\'压缩\', \'原图\', \'压缩或原图\'], countIndex: 8, count: [1, 2, 3, 4, 5, 6, 7, 8, 9], hasLocation: false, }, sourceTypeChange: function (e) { this.setData({ sourceTypeIndex: e.detail.value }) }, sizeTypeChange: function (e) { this.setData({ sizeTypeIndex: e.detail.value }) }, countChange: function (e) { this.setData({ countIndex: e.detail.value }) }, chooseImage: function () { var that = this wx.chooseImage({ //sourceType: sourceType[this.data.sourceTypeIndex], sizeType: sizeType[this.data.sizeTypeIndex], count: this.data.count[this.data.countIndex], success: function (res) { console.log(res) that.setData({ imageList: res.tempFilePaths }) } }) }, previewImage: function (e) { var current = e.target.dataset.src wx.previewImage({ current: current, urls: this.data.imageList }) }, //位置 chooseLocation: function () { var that = this wx.chooseLocation({ success: function (res) { console.log(res) that.setData({ hasLocation: true, location: formatLocation(res.longitude, res.latitude), locationAddress: res.address }) } }) }, clear: function () { this.setData({ hasLocation: false }) }, //表单提交 formSubmit: function(e) { console.error(\'form发生了submit事件,携带数据为:\', e); wx.redirectTo({ url: \'../index-list\', }) } })
//index.css
page {
  line-height: 1.6;
  font-family: -apple-system-font, "Helvetica Neue", sans-serif;
}
icon {
  vertical-align: middle;
}
.weui-cells {
  position: relative;
  margin-top: 1.17647059em;
  background-color: #FFFFFF;
  line-height: 1.41176471;
  font-size: 17px;
}
.weui-cells:before {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  
  color: #D9D9D9;
}
.weui-cells:after {
  content: " ";
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  height: 1px;
  
  color: #D9D9D9;
}
.weui-cells__title {
  margin-top: .77em;
  margin-bottom: .3em;
  padding-left: 15px;
  padding-right: 15px;
  color: #999999;
  font-size: 14px;
}
.weui-cells_after-title {
  margin-top: 0;
}
.weui-cells__tips {
  margin-top: .3em;
  color: #999999;
  padding-left: 15px;
  padding-right: 15px;
  font-size: 14px;
}
.weui-cell {
  padding: 10px 15px;
  position: relative;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
          align-items: center;
}
.weui-cell:before {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  
  color: #D9D9D9;
  left: 15px;
}
.weui-cell:first-child:before {
  display: none;
}
.weui-cell_active {
  background-color: #ECECEC;
}
.weui-cell_primary {
  -webkit-box-align: start;
  -webkit-align-items: flex-start;
          align-items: flex-start;
}
.weui-cell__bd {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
          flex: 1;
}
.weui-cell__ft {
  text-align: right;
  color: #999999;
}
.weui-cell_access {
  color: inherit;
}
.weui-cell__ft_in-access {
  padding-right: 13px;
  position: relative;
}
.weui-cell__ft_in-access:after {
  content: " ";
  display: inline-block;
  height: 6px;
  width: 6px;
  border-width: 2px 2px 0 0;
  border-color: #C8C8CD;
  border-style: solid;
  -webkit-transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
          transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
  position: relative;
  top: -2px;
  position: absolute;
  top: 50%;
  margin-top: -4px;
  right: 2px;
}
.weui-cell_link {
  color: #586C94;
  font-size: 14px;
}
.weui-cell_link:active {
  background-color: #ECECEC;
}
.weui-cell_link:first-child:before {
  display: block;
}
.weui-icon-radio {
  margin-left: 3.2px;
  margin-right: 3.2px;
}
.weui-icon-checkbox_circle,
.weui-icon-checkbox_success {
  margin-left: 4.6px;
  margin-right: 4.6px;
}
.weui-check__label:active {
  background-color: #ECECEC;
}
.weui-check {
  position: absolute;
  left: -9999px;
}
.weui-check__hd_in-checkbox {
  padding-right: 0.35em;
}
.weui-cell__ft_in-radio {
  padding-left: 0.35em;
}
.weui-cell_input {
  padding-top: 0;
  padding-bottom: 0;
}
.weui-label {
  width: 105px;
  word-wrap: break-word;
  word-break: break-all;
}
.weui-input {
  height: 2.58823529em;
  min-height: 2.58823529em;
  line-height: 2.58823529em;
}
.weui-toptips {
  position: fixed;
  -webkit-transform: translateZ(0);
          transform: translateZ(0);
  top: 0;
  left: 0;
  right: 0;
  padding: 5px;
  font-size: 14px;
  text-align: center;
  color: #FFFFFF;
  z-index: 5000;
  word-wrap: break-word;
  word-break: break-all;
}
.weui-toptips_warn {
  background-color: #E64340;
}
.weui-textarea {
  display: block;
  width: 100%;
}
.weui-textarea-counter {
  color: #B2B2B2;
  text-align: right;
}
.weui-textarea-counter_warn {
  color: #E64340;
}
.weui-cell_warn {
  color: #E64340;
}
.weui-form-preview {
  position: relative;
  background-color: #FFFFFF;
}
.weui-form-preview:before {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  
  color: #D9D9D9;
}
.weui-form-preview:after {
  content: " ";
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  height: 1px;
  border-bottom: 1rpx solid #D9D9D9;
  color: #D9D9D9;
}
.weui-form-preview__value {
  font-size: 14px;
}
.weui-form-preview__value_in-hd {
  font-size: 26px;
}
.weui-form-preview__hd {
  position: relative;
  padding: 10px 15px;
  text-align: right;
  line-height: 2.5em;
}
.weui-form-preview__hd:after {
  content: " ";
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  height: 1px;
  border-bottom: 1rpx solid #D9D9D9;
  color: #D9D9D9;
  left: 15px;
}
.weui-form-preview__bd {
  padding: 10px 15px;
  font-size: .9em;
  text-align: right;
  color: #999999;
  line-height: 2;
}
.weui-form-preview__ft {
  position: relative;
  line-height: 50px;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
}
.weui-form-preview__ft:after {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  
  color: #D5D5D6;
}
.weui-form-preview__item {
  overflow: hidden;
}
.weui-form-preview__label {
  float: left;
  margin-right: 1em;
  min-width: 4em;
  color: #999999;
  text-align: justify;
  text-align-last: justify;
}
.weui-form-preview__value {
  display: block;
  overflow: hidden;
  word-break: normal;
  word-wrap: break-word;
}
.weui-form-preview__btn {
  position: relative;
  display: block;
  -webkit-box-flex: 1;
  -webkit-flex: 1;
          flex: 1;
  color: #3CC51F;
  text-align: center;
}
.weui-form-preview__btn:after {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  bottom: 0;
  border-left: 1rpx solid #D5D5D6;
  color: #D5D5D6;
}
.weui-form-preview__btn:first-child:after {
  display: none;
}
.weui-form-preview__btn_active {
  background-color: #EEEEEE;
}
.weui-form-preview__btn_default {
  color: #999999;
}
.weui-form-preview__btn_primary {
  color: #0BB20C;
}
.weui-cell_select {
  padding: 0;
}
.weui-select {
  position: relative;
  padding-left: 15px;
  padding-right: 30px;
  height: 2.58823529em;
  min-height: 2.58823529em;
  line-height: 2.58823529em;
  border-right: 1rpx solid #D9D9D9;
}
.weui-select:before {
  content: " ";
  display: inline-block;
  height: 6px;
  width: 6px;
  border-width: 2px 2px 0 0;
  border-color: #C8C8CD;
  border-style: solid;
  -webkit-transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
          transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
  position: relative;
  top: -2px;
  position: absolute;
  top: 50%;
  right: 15px;
  margin-top: -4px;
}
.weui-select_in-select-after {
  padding-left: 0;
}
.weui-cell__hd_in-select-after,
.weui-cell__bd_in-select-before {
  padding-left: 15px;
}
.weui-cell_vcode {
  padding-right: 0;
}
.weui-vcode-img {
  margin-left: 5px;
  height: 2.58823529em;
  vertical-align: middle;
}
.weui-vcode-btn {
  display: inline-block;
  height: 2.58823529em;
  margin-left: 5px;
  padding: 0 0.6em 0 0.7em;
  border-left: 1px solid #E5E5E5;
  line-height: 2.58823529em;
  vertical-align: middle;
  font-size: 17px;
  color: #3CC51F;
  white-space: nowrap;
}
.weui-vcode-btn:active {
  color: #52a341;
}
.weui-cell_switch {
  padding-top: 6px;
  padding-bottom: 6px;
}
.weui-uploader__hd {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  padding-bottom: 10px;
  -webkit-box-align: center;
  -webkit-align-items: center;
          align-items: center;
}
.weui-uploader__title {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
          flex: 1;
}
.weui-uploader__info {
  color: #B2B2B2;
}
.weui-uploader__bd {
  margin-bottom: -4px;
  margin-right: -9px;
  overflow: hidden;
}
.weui-uploader__file {
  float: left;
  margin-right: 9px;
  margin-bottom: 9px;
}
.weui-uploader__img {
  display: block;
  width: 79px;
  height: 79px;
}
.weui-uploader__file_status {
  position: relative;
}
.weui-uploader__file_status:before {
  content: " ";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
}
.weui-uploader__file-content {
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
  color: #FFFFFF;
}
.weui-uploader__input-box {
  float: left;
  position: relative;
  margin-right: 9px;
  margin-bottom: 9px;
  width: 77px;
  height: 77px;
  border: 1px solid #D9D9D9;
}
.weui-uploader__input-box:before,
.weui-uploader__input-box:after {
  content: " ";
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
  background-color: #D9D9D9;
}
.weui-uploader__input-box:before {
  width: 2px;
  height: 39.5px;
}
.weui-uploader__input-box:after {
  width: 39.5px;
  height: 2px;
}
.weui-uploader__input-box:active {
  border-color: #999999;
}
.weui-uploader__input-box:active:before,
.weui-uploader__input-box:active:after {
  background-color: #999999;
}
.weui-uploader__input {
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}
.weui-article {
  padding: 20px 15px;
  font-size: 15px;
}
.weui-article__section {
  margin-bottom: 1.5em;
}
.weui-article__h1 {
  font-size: 18px;
  font-weight: 400;
  margin-bottom: .9em;
}
.weui-article__h2 {
  font-size: 16px;
  font-weight: 400;
  margin-bottom: .34em;
}
.weui-article__h3 {
  font-weight: 400;
  font-size: 15px;
  margin-bottom: .34em;
}
.weui-article__p {
  margin: 0 0 .8em;
}
.weui-msg {
  padding-top: 36px;
  text-align: center;
}
.weui-msg__link {
  display: inline;
  color: #586C94;
}
.weui-msg__icon-area {
  margin-bottom: 30px;
}
.weui-msg__text-area {
  margin-bottom: 25px;
  padding: 0 20px;
}
.weui-msg__title {
  margin-bottom: 5px;
  font-weight: 400;
  font-size: 20px;
}
.weui-msg__desc {
  font-size: 14px;
  color: #999999;
}
.weui-msg__opr-area {
  margin-bottom: 25px;
}
.weui-msg__extra-area {
  margin-bottom: 15px;
  font-size: 14px;
  color: #999999;
}
@media screen and (min-height: 438px) {
  .weui-msg__extra-area {
    position: fixed;
    left: 0;以上是关于微信小程序仿朋友圈 上传图片 定位的主要内容,如果未能解决你的问题,请参考以下文章

Android 实现仿微信朋友圈九宫格图片+NineGridView+ImageWatcher(图片查看:1.预览,2.拖动,3.放大,4.左右滑动,5.长按保存到手机)的功能

微信小程序图片上传时提示:没有应用可执行此操作

微信小程序多张图片上传

微信小程序生态图谱

进入微信小程序怎么发照片

微信小程序中如何上传图片