uploaddata.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view @click="toRecord()">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 30rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <view style="margin: 40rpx;">
  15. <uni-forms :modelValue="formData" validate-trigger="bind" err-show-type="undertext"
  16. label-width="150">
  17. <uni-forms-item name="play_number" label="小眼睛阅读数/播放量">
  18. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.play_number"
  19. placeholder="输入">
  20. </uni-easyinput>
  21. </uni-forms-item>
  22. <uni-forms-item name="like_number" label="点赞数">
  23. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.like_number"
  24. placeholder="输入">
  25. </uni-easyinput>
  26. </uni-forms-item>
  27. <uni-forms-item name="collect_number" label="收藏数">
  28. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.collect_number"
  29. placeholder="输入">
  30. </uni-easyinput>
  31. </uni-forms-item>
  32. <uni-forms-item name="comment_number" label="评论数">
  33. <uni-easyinput type="digit" maxlength=10 :inputBorder="false" v-model="formData.comment_number"
  34. placeholder="输入">
  35. </uni-easyinput>
  36. </uni-forms-item>
  37. </uni-forms>
  38. </view>
  39. <view style="margin: 0 40rpx;">
  40. <p style="margin-bottom: 20rpx;">上传小眼睛阅读数/播放量截图</p>
  41. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1" v-model="imageData"
  42. @chooseSuccess="ceshiChooseSuccess1">
  43. </htz-image-upload>
  44. </view>
  45. <view class="signup">
  46. <button type="default" class="but1" :loading="loading" @click="submit()">
  47. 提交数据</button>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import mvBar from "@/components/mys_navBar/mysNavBar";
  53. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  54. import getPolicyEncode from '@/components/obs/getPolicy.js';
  55. import getSignature from '@/components/obs/GetSignature.js';
  56. export default {
  57. components: {
  58. mvBar,
  59. htzImageUpload,
  60. },
  61. data() {
  62. return {
  63. navH: getApp().globalData.navHeight,
  64. taskId: "",
  65. dataStatus: "",
  66. imageData: [],
  67. formData: {
  68. play_number: "",
  69. like_number: "",
  70. collect_number: "",
  71. commet_number: "",
  72. },
  73. // rules: {
  74. // // 对play_number字段进行必填验证
  75. // play_number: {
  76. // rules: [{
  77. // required: true,
  78. // errorMessage: '10位以内的数字',
  79. // },
  80. // {
  81. // minLength: 1,
  82. // maxLength: 10,
  83. // errorMessage: '10位以内的数字',
  84. // }
  85. // ]
  86. // },
  87. // // 对like_number字段进行必填验证
  88. // like_number: {
  89. // rules: [{
  90. // required: true,
  91. // errorMessage: '10位以内的数字',
  92. // },
  93. // {
  94. // minLength: 1,
  95. // maxLength: 10,
  96. // errorMessage: '10位以内的数字',
  97. // }
  98. // ]
  99. // },
  100. // // 对collect_number字段进行必填验证
  101. // collect_number: {
  102. // rules: [{
  103. // required: true,
  104. // errorMessage: '10位以内的数字',
  105. // },
  106. // {
  107. // minLength: 1,
  108. // maxLength: 10,
  109. // errorMessage: '10位以内的数字',
  110. // }
  111. // ]
  112. // },
  113. // // 对comment_number字段进行必填验证
  114. // comment_number: {
  115. // rules: [{
  116. // required: true,
  117. // errorMessage: '10位以内的数字',
  118. // },
  119. // {
  120. // minLength: 1,
  121. // maxLength: 10,
  122. // errorMessage: '10位以内的数字',
  123. // }
  124. // ]
  125. // }
  126. // },
  127. mysNavConfig: {
  128. /* 开启单页显示首页图标 */
  129. isHome: true,
  130. /* 固定导航 */
  131. navFixed: true,
  132. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  133. navTitle: {
  134. text: "上传链接",
  135. color: "",
  136. fontSize: "32rpx", // px upx rpx
  137. fontWeight: "normal", // 100 - 700
  138. },
  139. btnType: "type2",
  140. onLeftClick: '',
  141. /* type2 按钮 */
  142. type2Config: {
  143. // 左图标
  144. leftPath: "/static/img/png2.png",
  145. // 右图标
  146. rightPath: "/static/img/png4.png",
  147. // 圆角
  148. radius: "40rpx",
  149. },
  150. },
  151. }
  152. },
  153. onLoad(options) {
  154. let data = options.textObj.replace(/""/g, "");
  155. data = JSON.parse(decodeURIComponent(data))
  156. this.taskId = data.taskId
  157. this.dataStatus = data.dataStatus
  158. this.getData()
  159. },
  160. methods: {
  161. getData() {
  162. this.$https.get('/youngee/c/t/g/get-unsubmit-task-data' +
  163. "?" +
  164. "task_id" +
  165. "=" +
  166. this.taskId)
  167. .then(res => {
  168. console.log(res)
  169. if (res.data.data != null) {
  170. this.formData.play_number = res.data.data.play_number
  171. this.formData.like_number = res.data.data.like_number
  172. this.formData.collect_number = res.data.data.collect_number
  173. this.formData.comment_number = res.data.data.comment_number
  174. this.imageData.push(res.data.data.photo_url)
  175. }
  176. })
  177. },
  178. toRecord() {
  179. var data = {
  180. taskId: this.taskId,
  181. };
  182. data = JSON.stringify(data)
  183. uni.navigateTo({
  184. url: '/pages/workspace/datarecord?textObj=' + encodeURIComponent(data)
  185. });
  186. },
  187. submit() {
  188. // 校验
  189. if (this.formData.play_number == "" || this.formData.like_number == "" || this.formData.collect_number ==
  190. "" || this.formData.comment_number == "") {
  191. uni.showToast({
  192. title: '请输入10位以内的数字',
  193. icon: 'none'
  194. })
  195. return
  196. }
  197. if (this.imageData.length == 0) {
  198. uni.showToast({
  199. title: "请上传正确的截图",
  200. icon: 'none'
  201. })
  202. return
  203. }
  204. // 调用添加链接接口
  205. this.$https.post('/youngee/c/t/p/add-task-data', {
  206. task_id: this.taskId,
  207. play_number: this.formData.play_number,
  208. like_number: this.formData.like_number,
  209. collect_number: this.formData.collect_number,
  210. comment_number: this.formData.comment_number,
  211. photo_url: this.imageData[0],
  212. })
  213. .then(res => {
  214. console.log(res)
  215. uni.navigateBack()
  216. })
  217. },
  218. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  219. console.log('ceshiChooseSuccess', tempFilePaths, e);
  220. if (e == 0) {
  221. this.store = 'talent_upload/' + this.guid() + '.png'
  222. } else if (e == 1) {
  223. this.store = 'talent_upload/' + this.guid() + '.mp4'
  224. }
  225. /****************
  226. 以下代码是自定义上传逻辑,仅供参考
  227. ***************/
  228. this.imgUpload1(tempFilePaths);
  229. /*******************************/
  230. console.log("imgdata" + this.imageData)
  231. },
  232. imgUpload1(tempFilePaths) {
  233. let that = this
  234. console.log('imgUpload', tempFilePaths)
  235. let config = {
  236. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  237. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  238. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  239. };
  240. let fileName = this.store; //指定上传到OBS桶中的对象名
  241. // let fileName = "talent_upload/icon-arrow-right.png"
  242. let OBSPolicy = { //设定policy内容
  243. "expiration": "2089-12-31T12:00:00.000Z",
  244. "conditions": [{
  245. "bucket": "horastar"
  246. }, //Bucket name
  247. // {"bucket": "goin"},
  248. {
  249. 'key': fileName
  250. }
  251. ]
  252. }
  253. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  254. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  255. uni.uploadFile({
  256. //url: config.EndPoint,
  257. url: config.EndPoint,
  258. filePath: tempFilePaths[0],
  259. name: 'file',
  260. formData: {
  261. 'AccessKeyID': config.AccessKeyId,
  262. 'policy': policyEncoded,
  263. 'signature': signature,
  264. 'key': fileName,
  265. },
  266. success: function(res) {
  267. console.log(res.statusCode); //打印响应状态码
  268. if (res.statusCode == '204') {
  269. that.imageData.push(config.EndPoint + '/' + fileName);
  270. console.log('上传图片成功', res)
  271. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  272. console.log(obs_url)
  273. // that.formData.home_img = obs_url
  274. uni.showToast({
  275. title: '上传成功',
  276. icon: '成功'
  277. });
  278. } else {
  279. console.log('上传图片失败', res)
  280. uni.showToast({
  281. title: '上传失败',
  282. icon: '失败'
  283. });
  284. }
  285. },
  286. fail: function(e) {
  287. console.log(e);
  288. uni.showToast({
  289. title: '上传失败22222',
  290. icon: '失败'
  291. });
  292. }
  293. })
  294. },
  295. guid() {
  296. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  297. var r = Math.random() * 16 | 0,
  298. v = c == 'x' ? r : (r & 0x3 | 0x8);
  299. return v.toString(16);
  300. });
  301. },
  302. }
  303. }
  304. </script>
  305. <style lang="scss" scoped>
  306. .signup {
  307. box-shadow: 0rpx 5rpx 40rpx #ccc;
  308. width: 100%;
  309. position: fixed;
  310. bottom: 0rpx;
  311. display: flex;
  312. height: 90rpx;
  313. padding-top: 2%;
  314. background-color: #FFFFFF;
  315. }
  316. .but1 {
  317. width: 60%;
  318. background-color: #f2d22d;
  319. border-radius: 20rpx;
  320. font-size: 36rpx;
  321. line-height: 200%;
  322. letter-spacing: 10rpx;
  323. font-weight: 500;
  324. height: 80%;
  325. &.on {
  326. background-color: #C0C0C0;
  327. }
  328. }
  329. </style>